Subject: Re: How to use su
To: None <firstname.lastname@example.org>
From: Gandhi woulda smacked you <email@example.com>
Date: 08/28/1999 19:42:24
On Sat, 28 Aug 1999 firstname.lastname@example.org wrote:
# first: YES I have read the man page!
# The question is how can i achieve the same as "su - USER -c 'COMMAND'"
# on Solaris with the NetBSD su.
Let's make one thing clear first off: Solaris 'su' is Broken As Designed as
it tries to use the .cshrc of the person who invoked the 'su' command.
[that's an opinion of a born-and-bred BSD user.]
# I tried su USER /bin/sh COMMAND but this reads my .cshrc!!! - definitely,
# and I have NO .profile!
This is odd - it should NOT be reading YOUR .cshrc! Only Solaris 'su'
You probably want
su - $USER -c '$COMMAND'
[you have to manually replace $COMMAND with its args]. This will cause
$USER's shell to be executed as
$SHELL -c '$COMMAND'
"su -" is silently backward-compatible with the more up-to-date "su -l".
I prefer the former.
"su -f" is an ancient hack which passes the "-f" flag to $USER's $SHELL
IFF $SHELL == /bin/csh (i.e. "su -f user" == "su user -f"). It remains
in a more documented form of backward compatibility, although I am not
certain why this is so (perhaps for root's sake).
# I also tried several combinations of options (-m -f etc), but never
# got the desired result.
# Some results include:
# # su apr /bin/csh w
# \340\231^C\340\377\275: Event not found.
There's two errors here:
1) You're trying to use your shell to parse /bin/csh as a script.
2) Even if this were not so, you'd be trying to use /bin/csh to
parse the script 'w' in the current directory, which is not
going to work unless you have such a script.
What you're looking for is:
# su apr -fc 'w'
Although the quotes are not necessary in this case, just as a stylistic
habit you might want to get used to typing them because if you are using
more than one word as your command you will need them.
As an example, I'm the only one allowed to su on my system (other users are
of cadet status (Can't Access - Don't Even Try)), so if I need super-user
access through them, I must do:
starwolf 2: su greywolf -c 'su -'
Or to become another user besides the one logged in:
su greywolf -c 'su root -c "su other_user"'
This can get REALLY messy if you extrapolate to its absurd extreme.
NetBSD: The power to Connect