Tilde substitution in ksh

Tilde substitution in ksh

Post by Alain Ninane - FY » Thu, 16 Feb 1995 22:38:36



Folks,
Is there a way to perform tilde substitution on variables with ksh ?
Briefly, the following shell:

Quote:> #! /usr/bin/ksh
> USERS="user1 user2 user3 user4"

> for user in $USERS; do
>    print ~$user
> done

> exit

Does not work as I would like, i.e. it prints ~user1, ~user2 instead
of the home directories ... :-( Do not reply me to get the home from
the passwd file (or nis map) with awk.  I'm aware of that solution but
I do not like it very much.

Thanks for your help,
Alain
--
Dr. Alain H. Ninane     | Tel : +32-10-47.32.32 - Fax: +32-10-45.21.83

Nuclear Physics Dept.   | Ch. du Cyclotron, 2
B-1348 Louvain-la-Neuve | BELGIUM              

 
 
 

Tilde substitution in ksh

Post by Mark Ra » Fri, 17 Feb 1995 08:51:46



Quote:>Is there a way to perform tilde substitution on variables with ksh ?

>>        print ~$user

Try
    eval print ~$user

This will scan the command twice, once expanding the $user, and once
expanding the home directory.

Hope this helps
--
Mark Rafn                    "If you're not part of the solution,


 
 
 

Tilde substitution in ksh

Post by Mario M. Butt » Fri, 17 Feb 1995 02:07:55



Quote:>Folks,
>Is there a way to perform tilde substitution on variables with ksh ?
>Briefly, the following shell:

>> #! /usr/bin/ksh
>> USERS="user1 user2 user3 user4"

>> for user in $USERS; do
>>        print ~$user
>> done

>> exit

>Does not work as I would like, i.e. it prints ~user1, ~user2 instead
>of the home directories ... :-( Do not reply me to get the home from
>the passwd file (or nis map) with awk.  I'm aware of that solution but
>I do not like it very much.

try:

eval print ~$user

---

Mario

Mario M. Butter


#include <std-disclaimer.h>

I see a dark sail on the horizon -
    set under a black cloud that hides the sun.
Bring me my broadsword, and clear understanding.
    Bring me my cross of gold as a talisman.
                     - Jethro Tull, Broadsword.

 
 
 

Tilde substitution in ksh

Post by Anand A. Kek » Sun, 19 Feb 1995 07:14:49



: > #! /usr/bin/ksh
: > USERS="user1 user2 user3 user4"
: >
: > for user in $USERS; do
: >  print ~$user
: > done
: >
: > exit

: Does not work as I would like, i.e. it prints ~user1, ~user2 instead
: of the home directories ... :-( Do not reply me to get the home from
: the passwd file (or nis map) with awk.  I'm aware of that solution but
: I do not like it very much.

Just do
     eval print ~$user
in place of
     print ~$user

- Anand

 
 
 

Tilde substitution in ksh

Post by John All » Sun, 19 Feb 1995 07:06:26



Quote:>Folks,
>Is there a way to perform tilde substitution on variables with ksh ?
>Briefly, the following shell:

>> #! /usr/bin/ksh
>> USERS="user1 user2 user3 user4"

>> for user in $USERS; do
>>        print ~$user
>> done

>> exit

>Does not work as I would like, i.e. it prints ~user1, ~user2 instead
>of the home directories ... :-( Do not reply me to get the home from
>the passwd file (or nis map) with awk.  I'm aware of that solution but
>I do not like it very much.

try:

eval print ~$user

John.

 
 
 

Tilde substitution in ksh

Post by Hrvoje Niks » Wed, 22 Feb 1995 21:09:00



Quote:> Folks,
> Is there a way to perform tilde substitution on variables with ksh ?
> Briefly, the following shell:
> > #! /usr/bin/ksh
> > USERS="user1 user2 user3 user4"

> > for user in $USERS; do
> >       print ~$user
> > done

> > exit
> Does not work as I would like, i.e. it prints ~user1, ~user2 instead
> of the home directories ... :-( Do not reply me to get the home from
> the passwd file (or nis map) with awk.  I'm aware of that solution but
> I do not like it very much.

I am afraid it is exacrly the only solution ksh can manage, because it
doesn't have builtin tilde expansion.  Try using bash instead.  It is more
or less compatible with ksh, and supports this feature.  Only, that line
should be:
eval echo \~$user

Hrv
--
Hrvoje Niksic                |

http://www.srce.hr/~hniksic/ |  University of Zagreb, Croatia
-------------------------------------------------------------------

Quote:>Is there any virus protections software for UNIX systems??

Yes.  It is called UNIX.
 
 
 

Tilde substitution in ksh

Post by Jon A. Maxwe » Thu, 23 Feb 1995 06:09:25


I am afraid you are incorrect, Mr. Niksic:
        eval print ~$(print $user)

In addition, this solution does not exec any new processes so it is fast and
system-friendly, and the same general form can be used for many similar
operations.


] > Is there a way to perform tilde substitution on variables with ksh ?

] > > #! /usr/bin/ksh
] > > USERS="user1 user2 user3 user4"
] > >
] > > for user in $USERS; do
] > >     print ~$user
] > > done
] > >
] > > exit

] > Does not work as I would like, i.e. it prints ~user1, ~user2 instead
] > of the home directories ... :-( Do not reply me to get the home from
] > the passwd file (or nis map) with awk.  I'm aware of that solution but
] > I do not like it very much.

] I am afraid it is exacrly the only solution ksh can manage, because it
] doesn't have builtin tilde expansion.  Try using bash instead.  It is more
] or less compatible with ksh, and supports this feature.  Only, that line
] should be:
] eval echo \~$user

--

        Jam

        maJ

 
 
 

1. Tilde substitution

Hi all,

Just one simple question: I got variable, lets say it MY_DIR, which is set
to ~/bin.

$ echo $MY_DIR
~/bin

It is of course set not from my fingers but as a result of some application.
The question is why the tilde is not substituted if I try:

$ ls $MY_DIR
~/bin: No such file or directory

Or better: how may I force ksh to substitute it to full name. I don't wanna
do the trick with combining 'logdir' and the remaining part (after ~/) of
$MY_DIR

I'll appreciate any help, tia

Pete

2. rc.d

3. ksh process substitution - which ksh's support this?

4. Getting symbols on XCOFF binary

5. serial-port cards

6. tilde in ksh directory prompt

7. Howto resize serial port(tty) input buffer

8. Tilde in ksh scripts

9. What's 'side effects' of Ksh built-ins?

10. "!" Substitution not working on Solaris Ksh

11. Filename substitution in ksh script

12. how to include <filename> as part of ksh substitution script?