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.
su - oracle
– MAQ Mar 06 '16 at 00:10-l
. It doesn't work. – Bernardo Vale Mar 06 '16 at 00:18su -
commands would expand in the current shell (not aftersu
). Using single-quotes would help. – Thomas Dickey Mar 06 '16 at 00:26getent passwd oracle
to find the right entry in the passwd database, regardless of whether it's in a local file, NIS, or LDAP. – alanc Mar 06 '16 at 15:55