Precedence in operators issue | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Precedence in operators issue

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-14-2011
arvindspr06 arvindspr06 is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 14 March 2011, 8:18 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Data Precedence in operators issue

Hello,
I am trying to write a small acript to change directory to $HOME depending on the user logged in. However when i provide this command
say,

ABC_USER=myself
cd ~${ABC_USER} i am getting the following error,

ksh: ~myself: not found

I know i am doing something really silly but not able to figure out what it is. I know i could get the value of the home directory by doing a grep on /etc/passed file but i think it is not a good solution.

Can anyone help or have encountered this issue before? I am thinking this issue is one of precedence where "~" is evaluated before the "$".

Anyone??
Sponsored Links
    #2  
Old 03-14-2011
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 16 September 2014, 5:14 PM EDT
Location: Ashburn, Virginia
Posts: 9,925
Thanks: 60
Thanked 434 Times in 259 Posts
It works for me...if the user is in /etc/passwd...

Code:
$
$ ABC=mail
$ grep mail /etc/passwd
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
$ cd ~${ABC}
$ pwd
/var/spool/mail
$
$ ABC=fubar
$ cd ~${ABC}
ksh: cd: ~fubar: [No such file or directory]
$

Sponsored Links
    #3  
Old 03-14-2011
arvindspr06 arvindspr06 is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 14 March 2011, 8:18 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for your quick reply Perdarabo.

I am using /bin/ksh . Could it be it does not work in that shell?

echo $SHELL. Can you tell me what shell you are using?
    #4  
Old 03-14-2011
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 16 September 2014, 5:14 PM EDT
Location: Ashburn, Virginia
Posts: 9,925
Thanks: 60
Thanked 434 Times in 259 Posts
I'm using ksh just like you. Look closely in my post toward the bottom. The shell id'ed itself in the error message. My OS was RedHat 5.
Sponsored Links
    #5  
Old 03-14-2011
arvindspr06 arvindspr06 is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 14 March 2011, 8:18 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks .. i fixed it by grepping the path from /etc/password and changing it to that location. However the below approach did not work for me on HPUX 11.23
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
issue with multiple logical operators nss280 UNIX for Dummies Questions & Answers 2 09-01-2010 09:54 PM
Makefile -> pc precedence over c quintet Programming 7 08-17-2008 10:08 AM
setting precedence with getopts jack1981 Shell Programming and Scripting 1 07-17-2006 09:57 AM
precedence of stderr and stdout new2ss Shell Programming and Scripting 1 06-08-2006 11:03 PM
EOF & precedence of != alan Programming 4 04-29-2004 02:47 PM



All times are GMT -4. The time now is 09:31 AM.