Skip to content

BASH Initialization on SLES

David Bank edited this page Dec 27, 2023 · 4 revisions

BASH Initialization Process

The BASH shell (/bin/bash) uses a number of initialization files to allow both the SysAdmin and/or the individual user to control and customize their shell environment. These are my notes from exploration on SLES v15.

Login or Non Login

Shells are either Login or Non-Login. A Login shell further may be Interactive or Non-Interactive. Generally, a Non-Login shell is always Non-Interactive.

  • An Interactive Login shell is generally seen in a process list with a preceding dash, like -bash. An example would be the shell session you enter when you SSH to a host.
  • A Non-Login shell is created when, for example, a script spawns a sub-shell, which it might do to execute a command.

The GNU BASH website has more information on this topic.

Initialization Files

Generally, a BASH shell that is Non-Interactive will look for the BASH_ENV environment variable. If the variable is defined and specifies a file that exists, then the shell will read and execute that file as its sole source of initialization.

In the SLES environment specifically, an Interactive Login shell will read and execute the following files, in the following order:

  • /etc/profile
  • /etc/profile.local
  • /etc/bash.bashrc
  • /etc/bash.bashrc.local
  • ~/.bashrc
  • ~/.bash_profile

That does seem to differ somewhat from the process described in the GNU documentation.

Assuming that the BASH_ENV environment variable is not defined, a Non-Interactive Non-Login shell will read and execute the following files, in the following order:

  • /etc/bash.bashrc
  • /etc/bash.bashrc.local
  • ~/.bashrc

It does not appear that the default BASH configuration in SLES reads ~/.profile, although it would certainly be possible to cause that to happen by invoking it from ~/.bashrc

Links

Clone this wiki locally