We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There are lots of ways to do this. I'm documenting some of them here, in case only one of them works on a particular OS.
A) STDIN_OWNERS_HOME=$(perl -MPOSIX -e'print((getpwuid((stat ttyname 0)[4]))[7])') B) STDIN_OWNERS_HOME=$(perl -e'print((getpwuid((stat shift)[4]))[7])' $(tty)) C) STDIN_OWNERS_HOME=$(eval echo ~$(who am i | cut -d ' ' -f 1)) D) STDIN_OWNERS_HOME=$(eval echo ~$(logname))
Test these after sudoing to root. If it works properly, it should show who the original user is.
Alternate ways of getting the same information include the effective-UID (only when running a setuid script), or $SUDO_USER (only when using 'sudo').
Places where the above don't work: