perl -e '@pw = getpwuid $< ; print $pw[8], "\n"'
This assumes that Perl is installed, configured correctly in your $PATH , which is a fairly safe bet on most modern Unix-like systems. (This is probably a safer bet than getent , or that the user's information is actually stored in the /etc/passwd or that the value of $SHELL not been changed.)
$< is the real UID of the current process. getpwuid() returns an array of values ββfrom /etc/passwd or any other mechanism used by the system (NIS, LDAP). Element 8 of this array is the user's login shell.
The above may be slightly reduced to:
perl -e 'print +(getpwuid $<)[8], "\n"'
or
perl -e 'print((getpwuid $<)[8], "\n")'
The reasons for the unary + operator or extra parentheses are pretty obscure.
Keith thompson
source share