Startup scripts

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search
← The tilde expansionHomeUsing aliases →

If you'd like to set the bash environment variables permanently, add your settings to the initialization file located in the home directory of your account $HOME/.bash_profile.

Script Execution Order

  1. /etc/profile - It contains Linux system wide environment and startup programs. This file runs first when a user logs in to the system. This file also act as a system-wide profile file for the bash shell.
  2. /etc/profile.d - /etc/profile calls /etc/profile.d/. It is a directory and all scripts in this directory are called by /etc/profile using a for loop. This file runs second when a user logs in.
  3. ~/.bash_profile or $HOME/.bash_profile - Finally, the file ~/.bash_profile is called in the users home directory ($HOME). This file runs third when a user logs in. This file calls ~/.bashrc in the users home directory.

Please note that each script can add or undo changes made in previously called script. For example, the PS1 variable is set in the /etc/profile, but it can be modified in the ~/.bash_profile or ~/.bashrc file.

Usage

  • Use above files to customize your environment.
  • Typical examples:
    1. Set PATH and PS1 (shell prompt) variables.
    2. Set default printer via PRINTER variable.
    3. Set default text editor via EDITOR variable.
    4. Set default pager via PAGER variable.
    5. Set default umask (file mode creation mask).
    6. Override and remove unwanted settings such as variables or aliases (undo changes).
    7. Set up environment.
    8. Set up aliases.
    9. Set up functions.

How do I view dot (.) files?

Type the following command in your $HOME directory:

ls -a

OR

ls -A | less

Sample outputs:

.bash_logout  .bash_profile  .bashrc  domain-check-2.txt  .mozilla  safe  s.img  test12  test1.csv  .zshrc

To view contains of the file, enter:

cat .bash_profile

OR

cat $HOME/.bash_profile

OR

cat ~/.bash_profile

See also

← The tilde expansionHomeUsing aliases →