Linux Know-How provides a collection of introductory texts on often needed Linux skills.


Bash startup files

Invoked as an interactive login shell, or with `--login'

Interactive means you can enter commands. The shell is not running because a script has been activated. A login shell means that you got the shell after authenticating to the system, usually by giving your user name and password.

Files read:

  • /etc/profile

  • ~/.bash_profile, ~/.bash_login or ~/.profile: first existing readable file is read

  • ~/.bash_logout upon logout.

Error messages are printed if configuration files exist but are not readable. If a file does not exist, bash searches for the next.

Invoked as an interactive non-login shell

A non-login shell means that you did not have to authenticate to the system. For instance, when you open a terminal using an icon, or a menu item, that is a non-login shell.

Files read:

  • ~/.bashrc

This file is usually referred to in ~/.bash_profile:

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

See Chapter 7 for more information on the if construct.

Invoked non-interactively

All scripts use non-interactive shells. They are programmed to do certain tasks and cannot be instructed to do other jobs than those for which they are programmed.

Files read:

  • defined by BASH_ENV

PATH is not used to search for this file, so if you want to use it, best refer to it by giving the full path and file name.

Invoked with the sh command

Bash tries to behave as the historical Bourne sh program while conforming to the POSIX standard as well.

Files read:

  • /etc/profile

  • ~/.profile

When invoked interactively, the ENV variable can point to extra startup information.

POSIX mode

This option is enabled either using the set built-in:

set -o posix

or by calling the bash program with the --posix option. Bash will then try to behave as compliant as possible to the POSIX standard for shells. Setting the POSIXLY_CORRECT variable does the same.

Files read:

  • defined by ENV variable.

Invoked remotely

Files read when invoked by rshd:

  • ~/.bashrc

WarningAvoid use of r-tools
 

Be aware of the dangers when using tools such as rlogin, telnet, rsh and rcp. They are intrinsically insecure because confidential data is sent over the network unencrypted. If you need tools for remote execution, file transfer and so on, use an implementation of Secure SHell, generally known as SSH, freely available from http://www.openssh.org. Different client programs are available for non-UNIX systems as well, see your local software mirror.

Invoked when UID is not equal to EUID

No startup files are read in this case.


Last Update: 2010-12-16