"The reasonable man adapts himself to the world; the unreasonable man persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw
14 Aug 2015 | virtualbox, virtualmachine, archlinux, linux, development, bash, script, etc, environment, pam
This post serves as a reference for various Linux startup, login and init scripts, environment variables and the order in which they are loaded or executed.
I use Arch Linux with Bash, but the general concepts should be applicable to any distro or shell. I also use Bash as my default login shell. You can confirm which login shell you’re running (sh or bash) by using echo $SHELL
. The default user shell can be changed using the chsh
command.
echo $VAR
will not work)FOO = Hi, I'm a variable & my name is FOO
$PATH
), /etc/bash.bashrc or /etc/profile (login shells only) are good options for doing it for all users. For user specific script commands ~/.bashrc can be used for non-login shells or either of .bash_profile, .bash_login or .profile for login shells.Note: SSH is an interactive login shell BUT it starts non-interactively. This is how I confirmed this:
echo
statements present in my $BASH_ENV script are executed while logging in via SSH, then this is proof enough that Bash is executing the $BASH_ENV script, which is only done for non-interactive shells. But more specifically, I used echo $-
.$-
is a special environment variable containing current shell options, if it contains i
, it is an interactive shell:$ echo $- himBH
echo $-
to your $BASH_ENV file, logging in via SSH will show something like hBc
confirming script execution and its non-interactive nature. All other scripts are executed in interactive mode.For login shells, Bash searches for & executes whichever script it finds in the following order of priority:
:
:
: