🐧 Linux / Shell Scripting
Advanced
What is the difference between login and non-login shells?
Answer
A login shell is started when a user first logs in (via console, SSH, su -). It sources: /etc/profile, then the first of ~/.bash_profile, ~/.bash_login, or ~/.profile. A non-login shell is started when opening a terminal emulator or running bash directly. It sources /etc/bash.bashrc and ~/.bashrc. Common confusion: changes to ~/.bashrc don't take effect in SSH sessions unless ~/.bash_profile sources it (which it should: [ -f ~/.bashrc ] && . ~/.bashrc). Interactive vs non-interactive: interactive shells read from a terminal; non-interactive (scripts) don't. Check with $- containing i, or [[ $- == *i* ]].