Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

How does PATH get its contents back after I restart the shell?

Writer Matthew Martinez

Exercise 2 from Missing Semester asks the following:

Run PATH= and try running the previous commands again, some work and some don’t, can you figure out why?

Setting PATH= removes all the contents from the PATH variable. Then echo $PATH yields just an empty line. But when I restart the shell, all the contents of the PATH variable are there again. My question is where does PATH variable get its values from when I restart the shell?

1 Answer

In general, every process inherits its environment (including a value for the PATH) from its parent. So if you start a shell from a terminal emulator, the shell inherits from the terminal which inherits from the desktop session and so on. If you follow the process tree back, you will find that a default PATH value is read from the /etc/environment file by the pam_env module when a user's session is initiated.

Additionally, if you are using Windows Subsystem for Linux (WSL), path components may be inherited from the Windows host session via the appendWindowsPath interoperability feature.

For the specific case of shells, the PATH variable may additionally be set or modified by various system-wide and/or user-specific configuration files, depending on

  • which shell you are using (bash, dash, ksh, zsh, csh etc.)
  • how the shell is invoked (as a login shell, as an interactive non-login shell, or as a non-interactive shell)

For bash, you can read the details in the INVOCATION section of man bash.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy