39

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?

2
  • nobody doesn't have a home! (It's nobody, the user.) Commented Apr 9, 2014 at 6:18
  • 2
    @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 Commented Apr 9, 2014 at 6:49

1 Answer 1

38

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

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.

1
  • 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). Commented Apr 10, 2014 at 0:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.