Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I heard (although I can't find any sources for proof) that the USER environment variable may not be set in a old Unix shells (maybe even some obscure shells as well). What is the probability that it won't be set?

share|improve this question
3:1. no, wait... 17:1. no, wait... – quack quixote Jan 29 '10 at 0:06
up vote 1 down vote accepted

The probability is very low.

if you want a fallback when writing a script:


...will default $USER if it's unset.

For really old pre-POSIX Bourne shells, you'd want:

test -z "$USER" && USER=`whoami`
share|improve this answer

Well, are you expecting to use any old shells, or are you expecting users of your program to do so?

Anyway, there's always id -un, though I have no idea whether this is more or less universal than $USER. You could have your script try both.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.