Bash - Login Shell

> Procedural Languages > Bash Shell and (Unix|Linux) Utilities (XCU)

1 - About

A login shell:

A login shell is a shell:

  • whose first character of argument zero ($0) is a -
  • or started with the –login or -l option. See Bash - Bash cli
Advertising

3 - Login and logout script

3.1 - Login

When bash is invoked as:

it reads and executes commands from the following files in this order:

  • /etc/profile,
  • ~/.bash_profile,
  • ~/.bash_login,
  • and ~/.profile,

The file must exists and be readable.

The –noprofile option may be used when the shell is started to inhibit this behavior.

3.2 - Logout

When a login shell exits, bash reads and executes commands from the files:

  • ~/.bash_logout
  • and /etc/bash.bash_logout

if the files exists.

Advertising

4 - Management

4.1 - Test

In a script, you can test if the shell is a login shell with this predicate.

argv[0][0] == '-'

5 - Documentation / Reference