Note that the info on this page is mainly generic to any \*nix machine and BASH.

What is run when BASH starts

See the Invocation section of man bash for a description of BASH's behaviour (attached below).

Login sessions are started by invoking BASH with the --login option or with the first option starting with -

Interactive is whenever you start BASH to get to a command prompt.

Non-interactive is when you run a bash script, with this invocation, the bashrc and profile login scripts are not rerun (there is a way to get an initialization script run in this instance, but that is a specialized use that I've never seen used...). You can create a non-interactive login shell by giving the proper options to BASH, though I don't see why you would want to.

(For the exact details of the above see the man page).

Interactive Login Shell

  • The system /etc/profile is run. On many systems this script invokes /etc/bashrc Note that BASH itself doesn't invoke /etc/bashrc for login shells.
  • The first and only the first found of ~/.bash_profile, ~/.bash_login, or ~/.profile is run.

Interactive Non-login shell

  • The system /etc/bashrc is run.
  • The user's ~/.bashrc is run.

What XTerm and Terminal do on MAC

Terminal gives you an interactive login shell. xterm gives you an interactive non-login shell, remember that if you launch xterm from the command-line, it will be a sub-process of that shell and inherit the environment. xterm -ls gives you an interactive login shell.

X11 Menu When you launch a program from the X11 menu, the process first gets an interactive non-login environment; /etc/bashrc and ~/.bashrc are run. So if you launch xterm this way, the init scripts run are: /etc/bashrc, ~/bashrc, /etc/bashrc, ~/.bashrc.

A Way to See Which Scripts Run...

I added code like this to /etc/profile /etc/bashrc ~/.profile and ~/.bashrc to show how these scripts run:

# init script execution record var...
export INITHIST="${INITHIST}__PROFILE_"`date "+%H:%M:%S"`"__"

-- TomRockwell - 01 Jun 2007
Topic attachments
I Attachment Action Size Date Who Comment
bash-invocation.txttxt bash-invocation.txt manage 4.6 K 01 Jun 2007 - 20:56 TomRockwell Section of BASH man page
Topic revision: r8 - 05 Jun 2007, TomRockwell
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback