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?
1 Answer
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.
-
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 'SO- stop being evil'– Gilles 'SO- stop being evil'2014-04-10 00:50:02 +00:00Commented Apr 10, 2014 at 0:50
nobodydoesn't have a home! (It'snobody, the user.)/etc/passwd