How to do it...
These files are evaluated when a user logs into a shell:
/etc/profile, $HOME/.profile, $HOME/.bash_login, $HOME/.bash_profile /
If a .bash_profile or .bash_login file is present, a .profile file will not be read.
These files will be read by an interactive shell such as a X11 terminal session or using ssh to run a single command like: ssh 192.168.1.1 ls /tmp.
/etc/bash.bashrc $HOME/.bashrc
Run a shell script like this:
$> cat myscript.sh #!/bin/bash echo "Running"
None of these files will be sourced unless you have defined the BASH_ENV environment variable:
$> export BASH_ENV=~/.bashrc $> ./myscript.sh
Use ssh to run a single command, as with the following:
ssh 192.168.1.100 ls /tmp
This will start a bash shell which will evaluate /etc/bash.bashrc and $HOME/.bashrc, but not /etc/profile or .profile.
Invoke a ssh login session, like this:
ssh 192.168.1.100
This creates a new login bash shell, which will evaluate the following:
/etc/profile /etc/bash.bashrc $HOME/.profile or .bashrc_profile
Use these files to define non-exported items such as aliases desired by all users. Consider this example:
alias l "ls -l" /etc/bash.bashrc /etc/bashrc
Use these files to hold personal settings. They are useful for setting paths that must be inherited by other bash instances. They might include lines like these:
CLASSPATH=$CLASSPATH:$HOME/MyJavaProject; export CLASSPATH $HOME/.bash_login $HOME/.bash_profile $HOME/.profile
Use these files to hold your personal values that need to be defined whenever a new shell is created. Define aliases and functions here if you want them available in an X11 terminal session:
$HOME/.bashrc, /etc/bash.bashrc
This file is evaluated when a user logs out of a session:
$HOME/.bash_logout
For example, if the user logs in remotely they should clear the screen when they log out.
$> cat ~/.bash_logout # Clear the screen after a remote login/logout. clear