Previous Page | Next Page

  1. Introduction
  2. Abbreviated Boot
  3. The Boot Process
  4. Startup and Run Levels
  5. Initialization Scripts
  6. Runlevel Scripts
  7. Login Process
  8. Bash Shell
  9. Filesystems
  10. LILO, Kernel and Root Filesystem
  11. The Kernel
  12. Passwords, Users, Groups, and Quotas
  13. The Environment
  14. The /etc/sysconfig directory
  15. The /proc filesystem
  16. Process Control
  17. Devices
  18. Daemons Services
  19. Inetd and Network Services
  20. Programs and Libraries
  21. Security and PAM
  22. The printer services
  23. Mouse support with gpm
  24. Mail
  25. News
  26. UUCP
  27. LDAP
  28. NFS and RPC
  29. Samba, NetBIOS, WINS, nmbd
  30. Identd (auth)
  31. Telnet and FTP
  32. Apache web server
  33. DNS and named
  34. How X Works
  35. X Scripts
  36. Support for Text
  37. Keymapping for Programs
  38. Keycode Table
  39. Example Keymap File
  40. Terminfo Commands
  41. VT100 ESC sequences
  42. Kernel Revisited
  43. Configuration Files
  44. Credits

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):

  1. The /etc/profile script file.
  2. 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.
    1. $HOME/.bash_profile
    2. $HOME/.bash_login
    3. $HOME/.profile
  3. 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.

Bash behavior

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:

  1. Pipelines using the | symbol
  2. Redirection with <, >, <<, >>
  3. Parameter expansion
  4. Environment variables - There is an extensive list.
  5. History - An ability to bring back previous commands using a command history list
  6. 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
  7. builtins - Bash supports an extensive array of builtin commands
For more information on this and other bash information read:
  1. The bash(1) man page
  2. The Bash Reference Manual in the directory /usr/doc/bash2-doc-2.03/bash.ps
  3. Bash builtins in the directory /usr/doc/bash2-doc-2.03/builtins.ps

Your directory names may vary slightly depending on your bash version.