Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

Assuming the machine is running a Linux kernel, sessions make use of the Bash shell and everything is using default configurations (no user has made any changes to config files), can we assume that the $HOME environment variable is always set?

share|improve this question
nobody doesn't have a home! (It's nobody, the user.) – devnull Apr 9 '14 at 6:18
@devnull not having a home (ie. having a home directory specified that doesn't exist), doesn't mean the $HOME env. variable cannot be set. If it is set, it just doesn't have to point to an existing directory nor to the home entry in /etc/passwd – Anthon Apr 9 '14 at 6:49
up vote 8 down vote accepted

Yes. The POSIX specification requires the OS to set a value for $HOME:

The system shall initialize this variable at the time of login to be a pathname of the user's home directory. See pwd.h.

What about user nobody?

# su - nobody
No directory, logging in with HOME=/
$ echo $HOME

Even though nobody has no true home, HOME is set to the root directory.

share|improve this answer
It isn't the shell that sets HOME — none of the common shells does except zsh. It's the program that logs you in (including methods like cron). – Gilles Apr 10 '14 at 0:50
@Gilles Thanks. Fixed. – John1024 Apr 10 '14 at 1:33

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.