Operating System - HP-UX
1755624 Members
3282 Online
108836 Solutions
New Discussion юеВ

Re: Tilde AND variable translations (ie ~$user)

 
Leslie Chaim
Regular Advisor

Tilde AND variable translations (ie ~$user)

After working on this problem for a while I found that there was a difference between sh and ksh:

$ user=lzc
$ ll -d ~$user
drwxrwx--- 18 lzc 100 4096 Sep 10 10:51 /mnt/lzc
$ export user
$ ksh
$ ll -d ~$user
~lzc not found
$ sh
$ ll -d ~$user
drwxrwx--- 18 lzc 100 4096 Sep 10 10:51 /mnt/lzc
$ ksh
$ ll -d ~$user
~lzc not found
$ ll -d ~lzc
drwxrwx--- 18 lzc 100 4096 Sep 10 10:51 /mnt/lzc
$ sh
$ ll -d ~$user
drwxrwx--- 18 lzc 100 4096 Sep 10 10:51 /mnt/lzc

Obviously, ksh can handle ~$user. Is there any way around this?
If life serves you lemons, make lemonade
6 REPLIES 6
Rodney Hills
Honored Contributor

Re: Tilde AND variable translations (ie ~$user)

You could try-

eval ll -d ~$user

This would force ksh to expand $user first, then execute "~" on it.

my 2 cents...

-- Rod Hills
There be dragons...
Leslie Chaim
Regular Advisor

Re: Tilde AND variable translations (ie ~$user)

Yes, eval works and its more then 'just 2 cents' :)

But, I don't like it :(
If it works with sh it should also work with ksh.

BTW, I am experiencing difficulties when assigning points. I click on the drop down list and make my selections then I click submit and I DO get the acknowledgments. But when I click to go back to the message the points disappear.

Please assist.
Thanks
lzc
If life serves you lemons, make lemonade
Tom Maloy
Respected Contributor

Re: Tilde AND variable translations (ie ~$user)

You might also try

ll -d $HOME/$user

Different shells, different ways of doing things.

HTH

Tom
Carpe diem!
Leslie Chaim
Regular Advisor

Re: Tilde AND variable translations (ie ~$user)

Tom,

This just will not work. Say user=lzc and I am logged in as emp:

echo ~
gives you /mnt/emp
echo $HOME
also gives you /mnt/emp
what will echo $HOME/$user do ;)

Though eval does it I am Still looking.
If life serves you lemons, make lemonade
Rodney Hills
Honored Contributor

Re: Tilde AND variable translations (ie ~$user)

Tom,

$HOME is relative to the current running session, not the one used by $user.

If henry ran the script with user=susan, you would get - /home/henry/susan

...

It is too bad that they don't behave the same. ksh for the most part can be a superset of sh, but it looks like you found the exception.

-- Rod Hills
There be dragons...
Tom Maloy
Respected Contributor

Re: Tilde AND variable translations (ie ~$user)

Egad. Good thing I'm not driving.

I meant

/home/$user

or wherever your user's home directories are...

Tom

Carpe diem!