The Linux Bash Shell
This page currently documents the bash shell. For information on other shells you will want to read their respective man pages and/or shell documentation.
Login invokes the shell program at the user's privilege level. One of the things bash will do is to look in the /etc/passwd file to get the name of the user. It will use the UID number to find the username and set the environment variable, USERNAME, to that value. If bash cannot read the /etc/password file it will put the string "I have no name" in the environment variable. If this happens, it is because the permissions on the /etc/passwd file are not set properly. The permissions should be "-rw-r--r--". This file must be set so all users can read it. Therefore it is a wise security precaution (and currently a standard) to implement shadow passwords so the users' encrypted passwords are stored in the /etc/shadow file only readable by root. See the section on passwords, users, and groups for more information.
Files run when bash starts
When bash starts it runs script files in the following order if the files exist and if the shell is a login shell (called by the login program):
- The /etc/profile script file.
- The .bash_profile script in the user's home directory referred to as $HOME/.bash_profile or ~/.bash_profile. If it is missing $HOME/.bash_login is run. If both .bash_profile and .bash_login are missing $HOME/.profile is run. Only one of these files is run. The one run is the first one of the list found.
- When bash exits the file called .bash_logout in the user's home directory is run.
On many Redhat distributions if the file ".bashrc" exists in the user's home directory it is run from the .bash_profile script. The .bashrc program will modify the path.
If the shell is not invoked by the login program, such as in single user mode (runlevel 1) bash will run the program .bashrc in the user's home directory. This is assuming the -norc option or the -rcfile option was not passed to bash to cancel running .bashrc or use another file.
Many bash commands are used in script programming. The script programming manual will give better insight into the use of these commands. Some noteworthy items supported by bash include:
For more information on this and other bash information read:
- Pipelines using the | symbol
- Redirection with <, >, <<, >>
- Parameter expansion
- Environment variables - There is an extensive list.
- History - An ability to bring back previous commands using a command history list
- Special characters for setting up the PS1 and PS2 prompt strings:
- \t - time
- \d - date
- \n - newline
- \s - Shell name
- \W - The current working directory
- \w - The full path of the current working directory.
- \u - The user name
- \h - Hostname
- \# - The command number of this command.
- \! - The history number of the current command
- builtins - Bash supports an extensive array of builtin commands
- The bash(1) man page
- The Bash Reference Manual in the directory /usr/doc/bash2-doc-2.03/bash.ps
- Bash builtins in the directory /usr/doc/bash2-doc-2.03/builtins.ps
Your directory names may vary slightly depending on your bash version.