Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why "cd ~username" OK but "cd ~$USERNAME" not OK ?

Status
Not open for further replies.
Apr 18, 2001
6
0
0
AU
I want to change to the home directory of user1

Code:
cd ~user1

that works fine but if I use a variable for username

Code:
USERNAME=user1
cd ~${USERNAME}[\code]

I get error message:

[b]ksh: ~user1: not found[/b]
 
you could try

USERNAME=user1
export USERNAME
cd ~${USERNAME}

I hope this helps.
 
The export didn't make any difference - it still doesn't work?

oracle@nuh105-/ora/admin/bin> ME=`who am i | cut -f1 -d" "`
oracle@nuh105-/ora/admin/bin> export ME
oracle@nuh105-/ora/admin/bin> echo $ME
c950849
oracle@nuh105-/ora/admin/bin> ls -lsa ~${ME}
~c950849 not found
oracle@nuh105-/ora/admin/bin> ls -lsa ~c950849
total 28
2 drwxr-x--- 3 c950849 oraadm 1024 Apr 19 14:22 .
2 drwxrwxrwx 27 oracle oraadm 1024 Apr 18 15:10 ..
2 -rw-r----- 1 c950849 oraadm 74 Apr 19 14:22 .all_nigel_profile
2 -rw-r--r-- 1 c950849 oraadm 814 Apr 18 15:10 .cshrc
2 -rw-r--r-- 1 c950849 oraadm 347 Apr 18 15:10 .exrc
2 -rw-r--r-- 1 c950849 oraadm 341 Apr 18 15:10 .login
2 -rw-r----- 1 c950849 oraadm 70 Apr 19 14:17 .my_oracle_shortcuts
2 -rw-r----- 1 c950849 oraadm 402 Apr 19 14:11 .my_unix_shortcuts
2 -rw-r----- 1 c950849 oraadm 136 Apr 19 15:23 .myvi
2 -rw-r--r-- 1 c950849 oraadm 494 Apr 19 14:22 .profile
6 -rw------- 1 c950849 oraadm 1884 Apr 19 16:14 .sh_history
0 drwxr-x--- 4 c950849 oraadm 96 Apr 19 14:16 bin
2 -rw-r----- 1 c950849 oraadm 458 Apr 19 09:41 myhosts
 
What do you see if you write "whoami"

 
Very strange ... it all works fine for me in ksh!

Greg.
 
Unixadmin: I get -

Code:
oracle@nuh105-/ora/admin/bin> whoami
oracle
oracle@nuh105-/ora/admin/bin> who am i
c950849    ttyp5        Apr 20 09:22
 
Do you logon first as c950849 and is your second logon oracle?
And i think if you write ;
ME=`whoami | cut -f1 -d" "`
export ME
echo $ME

you will get oracle.Is this what you want?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top