Difference: MacOSXLoginScripts (r6 vs. r5)

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

xterm produces an Interactive Non-login shell. xterm -ls produces an interactive login shell. Terminal gives you an interactive login shell. These follow the rules above.

When you login to a machine with ssh, you get an interactive login shell. However, if you use ssh to just run a command remotely, an interactive non-login shell is used (just bashrc scripts are run).

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 vars...
# 1 => /etc/bashrc
# 2 => /etc/profile
# 4 => ~/.bashrc
# 8 => ~/.profile
let "INITHIST = INITHIST | 0"
export INITHIST_ETC_PROFILE=$INITHIST
let "INITHIST = INITHIST | 2"
export INITHIST

-- TomRockwell - 01 Jun 2007

IAttachmentActionSizeDateWhoComment
bash-invocation.txttxtbash-invocation.txtmanage 4.6 K 01 Jun 2007 - 20:56TomRockwell Section of BASH man page

View topic | View difference side by side | History: r8 < r7 < r6 < r5 | More topic actions
 
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