I'm trying to get user $HOME variable over su. Solaris# su oracle$ echo $HOME/rootAIX# su oracle$ echo $HOME/Linux# su oracle$ echo $HOME/home/oracleCan someone explain why on Solaris and AIX when I try to get $HOME variable it gets the root's $HOME directory?UPDATEUsing login with with - or -l works, but I can't use su - on my script. Any thoughts on how to overcome this?I was trying to not use a solution like the above but I'm getting out of optionscat /etc/passwd | grep oracle | cut -d: -f 6or as Thomas suggested:cat /etc/passwd | awk -F: '$1 ~ /^'oracle'$/ {print $6;}'
Can't get user $HOME over su on Solaris and AIX
solaris;aix;su
Actually (quick check) su (from a non-privileged user to another non-privileged user) on Solaris does not modify $HOME at all.  Perhaps you were root when issuing the su command.The Solaris manual page is silent on the matter, but it is a known issue, quoting from a newsgroup comment:nails September 16, 2008 at 18:16:45    jefro:    Sorry I must disagree wtih you. At least in Solaris su <user id>    doesn't change the user environment - including environmental    variables. To change the environment, you must execute        su - <user id>    According to the su MAN page:    If the first argument to su is a dash (-), the environment will    be changed to what would be expected if the user actually logged    in as the specified user.However, the manual page says things about several variables, but not HOME:   o  In addition to what is already propagated, the LC*  and      LANG  environment  variables  from the specified user's      environment are also propagated.   o  Propagate TZ from the user's environment. If TZ is  not      found  in  the user's environment, su uses the TZ value      from    the     TIMEZONE     parameter     found     in      /etc/default/login.   o  Set MAIL to /var/mail/new_user. If the first argument to su is a dash (-),  the  environment will  be changed to what would be expected if the user actu- ally  logged  in  as  the  specified  user.  Otherwise,  the environment  is  passed  along, with the exception of $PATH, which is controlled by PATH and SUPATH in /etc/default/su.That last sentence can be construed to say that the current user's HOME variable is passed through without change (unless you use the su - form, of course).Other systems:The AIX manual page is less helpful, but since the feature is very old in both, the behavior may be based on the same source code.HPUX manual page is also not helpful, saying that The previously defined HOME and ENV environment variables are removed.Because su is not giving you the information you need, a different approach would help.  If your accounts all are local accounts (no LDAP), you can always search /etc/passwd, e.g.,THATHOME=$( awk -F: '$1 ~ /^'$THATUSER'$/ {print $6;}' </etc/passwd )Notes:the format of /etc/passwd is the same on all Unix-like systems.using awk to split up the field into fields avoids the problem with a grep picking up the wrong line (or lines), e.g., if you had an oracleadmin account.If you had LDAP, you might have the utility getent which would allow referring to non-local users.