Interview Prep/Shell Scripting/Shells, scripts and execution

What is the difference between a login, interactive and non-interactive shell, and which startup files run?

IntermediateConceptShells, scripts and execution
Answer
  • Login shell (SSH login, bash -l): reads /etc/profile, then the first of ~/.bash_profile, ~/.bash_login, ~/.profile.
  • Interactive non-login (new terminal tab): reads ~/.bashrc.
  • Non-interactive (scripts, cron, ssh host cmd mostly): reads nothing, except the file named in $BASH_ENV.

This is why a script works in your terminal but fails in cron: the PATH, aliases and variables from .bashrc are not there. Scripts must set everything they need themselves.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Shells, scripts and execution