Skip to content

Shell Basics | Linux - Wyatt's Notes

A shell is both an interactive command interpreter and a scripting language interpreter. When you open a terminal emulator, it spawns a shell process — bash``zshOr dash. When you run a script with ./script.shThe shebang line determines which interpreter processes The file.

AspectInteractiveNon-Interactive
Startup files.bashrc``.profile``/etc/bash.bashrcOnly BASH_ENV variable if set
PromptPS1``PS2 displayedNo prompt
Job controlEnabled (set -m)Disabled by default
Line editingReadline active (readline library)Not active
AliasesExpandedExpanded (in bash) or not (POSIX mode)
Exit on errorDoes not exit on errorSame unless set -e

The shell”s startup sequence differs depending on whether it is a login shell or a non-login Shell:

  • Login shell: Sourced on first login (SSH, su -``login). Reads /etc/profileThen ~/.bash_profile or ~/.bash_login or ~/.profile (first one found).
  • Non-login interactive shell: Reads ~/.bashrc.
  • Non-login non-interactive shell: Inherits exported environment variables. Does not read startup files unless BASH_ENV points to one.
flowchart TD
A[Shell Invoked] --> B{Login Shell?}
B -->|Yes| C{Interactive?}
B -->|No| D{Interactive?}
C -->|Yes| E[/etc/profile]
E --> F[~/.bash_profile]
F --> G[~/.bashrc]
C -->|No| H[BASH_ENV]
D -->|Yes| I[~/.bashrc]
D -->|No| J{BASH_ENV set?}
J -->|Yes| K[Source BASH_ENV]
J -->|No| L[No startup files]