Solaris 11 Changes: Where is /usr/ucb/whoami ?

Submitted by Stefan Schneider on Thu, 03/03/2011 - 16:40

Answer: It's still available through /usr/ucb/whoami . The difference to Solaris 10 is, that this command became part of an optional package as described in a previous post. The BSD commands are still available through this package. They are deprecated and it is not a good idea to use this command since it may be removed in future.

Just in case: The whoami  command displays the effective user:

sschneid@krachkaste:/home/sschneid $ whoami
sschneid

Option for Solaris 11 (only...)

Stop using this command in /usr/ucb/whoami and use the GNU version of the command which is available in /usr/bin/whoami. The command is a different implementation. It doesn't matter since whoami has no options and it's doing the same by showing the effective user.

Anyone who is using a search path with /usr/bin before /usr/ucb/bin and a relative command invocation will not see any problems in Solaris 10 or 11.

What to do if the command is hard coded and it is supposed to work on Solaris 10 and Solaris 11 without any changes in the script?

Option for Solaris 10 and Solaris 11

The pity is that /usr/ucb/whoami is available by default only on Solaris 10. /usr/bin/whoami is available only on Solaris 11.

Solution: Switch from the whoami command to the 

/usr/xpg4/bin/id -un

command. It shows as well the effective user and it is available on both versions of Solaris by default in the same place

It's not an option to use /usr/bin/id on Solaris 10 since it is not the xpg4 compliant implementation and it doesn't accept the -un option. The Solaris 11 version of /usr/bin/id is able to master the trick since it is xpg4 compliant.

Alternative option (honorable mention): The commmand 

$ expr "`id`" : '.*(\(.*\)) gid='

will do the trick as well on Solaris 10 as well as 11. It extracts the effective user with expr. (contributed by Joachim Wolf).