You can grep in the /etc/passwd file for current username, and use cut to extract the appropriate column of information:
grep ^$(id -un): /etc/passwd | cut -d : -f 7-
$(id -un)
is a safer than $USER
to get user name. Using ^
in front of user name and :
after makes sure you don't get a false match if your user name is a sub section of someone else user name.
$SHELL
can also be used, as suggested. However it won't work if chsh
was used in current shell, as the variable is not updated. Also the variable is not protected against being changed, so it can theoretically be set to something completely different.
Update to attempt an OS X compatible solution. Probably not optimal regexp:
grep ^.*:.*:$(id -u): /etc/passwd | cut -d : -f 7-
This is based on user id's. If the whole user entry is missing, not only user name, then osx must store this somewhere else.