Bash

created onJune 13, 2026

modes of operation

  • interactive shell – commands are run with user-interaction from keyboard. I.e., the shell can prompt the user to enter input.
  • non-interactive shell – the shell is run from an automated process (i.e. during the boot-sequence)
  • login shell – the shell is run as part of the login of a user.
  • non-login shell – any shell run by the user after logging in. Any shell that is run by any automated process which is not coupled to a logged-in user (i.e. during the boot-sequence).

interactive vs non-interactive

Interactive shell:

  • is started without non-option arguments (unless is specified) and without specifying the option.
  • stdin and stderr are connected to terminals.

or

  • is started with the option.

For interactive shells is set .It is not set for non-interactive shells. For interactive shells the special var contains ‘i’.

To test within a script whether a shell is interactive:

[[ $- == *i* ]] && printf "%s" "interactive" || printf "%s" "not interactive"

or

[[ -z "$PS1" ]] && printf "%s" "not interactive" || printf "%s" "interactive"

startup files

invoked as an interactive login shell

On startup, Bash looks for the following files, in the order given below, and for those files that exist, and executes the commands in those files:

The option inhibits this behaviour.

Usually contains code to execute commands in as well:

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

a shorter form of this is

[[ -f ~/.bashrc ]] && . ~/.bashrc

When Bash as an interactive login shell terminates, it looks for and executes the commands in therein.

invoked as an interactive non-login shell

On startup, Bash executes commands from ~/.bashrc, if that file exists. The option inhibits this behavior. The file option causes Bash to use file instead of .

built-in commands

Shells also provide a small set of built-in commands (built-ins). Some functionality is impossible or inconvenient to obtain via commands that are not built-in (built into the shell). For example, cd, break, continue, and exec directly manipulate the shell itself, which an external commands obviously cannot.

history, getopts, kill, or pwd built-ins could be implemented in separate commands, but they are more convenient to use as built-in commands.

x