OSXFAQ Mac OS X UNIX Tip-of-the-Day

Week 105 - Controlling Bash At Startup (18 April 2005)
by
Adrian Mayo - Editor, OSXFAQ
Monday - Background Information
Bash can be started as a login shell or as a non-login shell. One of the most significant differences between the two modes is the initialisation scripts sourced when Bash starts up.
A login shell sources the login scripts:
/etc/profile
~/.bash_profile
(If ~/.bash_profile cannot be read, ~/.bash_login is sourced, and if this can't be read, ~/.profile is sourced.)
On exit a login shell sources ~/.bash_logout.
A non-login shell sources the following scripts:
/etc/bashrc
~/.bashrc
NOTE: according to the bash manual, /etc/bashrc is not sourced, but it is.
When Apple's Terminal.app starts a new terminal session it starts a Bash login shell. When X11's xterm starts a new terminal session it starts a Bash non-login shell.
When you type 'bash' at the command line a non-login shell is started.
Non-interactive shells. When you run a shell script, a new shell is launched to execute the script. The new shell is a non-interactive (non-login) shell. It does not source any scripts on startup.
A non-login shell is exited by 'exit', and a login shell by 'logout'. Typing 'exit' in a login shell will run 'logout'.
If you want to learn more about Mac OS X Unix visit the Learning Center
click.
- For beginners: Mac OS X Unix Tutorials
- For detailed information on specific topics: Advanced Unix
- For OS X in gereral: Mac OS X Tutorials
|