1

So far I've used something like this in scripts, aliases and in the shell:

qstat -u $USER 

Now I found out that neither the $USER variable nor $USERNAME is not a built-in in bash. While $UID and $EUID are.

I could of course use $(whoami) or stuff like that. There are thounds of ways to find out the user name of the current process. But what's the best, most protable and short one of them and why?

1
  • POSIX requires $LOGNAME to be set, but mentions that $USER is also used. Don't base security decisions on the value of $LOGNAME or $USER because I can do USER=root and LOGNAME=root even if I'm logged in as pleb. Commented Apr 26, 2012 at 14:30

2 Answers 2

6

whoami looks deprecated. What about the suggestion of id -un?

The whoami utility has been obsoleted by the id(1) utility, and is equivalent to ``id -un'.

Sign up to request clarification or add additional context in comments.

Comments

2

Typically, $LOGNAME is defined with the name of the current user.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.