Command Post: Using the Shell *UPDATED*
Command Post is a series designed increase your understanding of a given command, it’s configuration files, usage and tips for exam questions about the command.
Understanding Shells
A shell is a program designed to interpret the commands users type, parse for expansions and wildcards, and then produce instructions to the computer to accomplish those tasks.
Unless you change the defaults, the Linux shell is normally the bash shell. Of course, many other shells exist. A partial list is shown in the following table.

Among other pieces of information, the user’s default shell is specified in the /etc/passwd entry for that user. If the shell that is specified does not exist, the user is not permitted to log in.
Special shells can be specified, such as /bin/false (which returns a nonzero error code, effectively blocking access by a user attempting to log in) or /etc/nologin (which is used to block logins for accounts that have been disabled and echo a message that login is denied). The /etc/nologin file might not exist on some systems.
Deconstructing a Login Shell Session
A login shell is one that is executed when logging in to the system. The /etc/profile file is the global configuration file that affects all users’ environments if they use the bash shell. It’s sourced (read) every time a user performs a login shell. This file is a script and is executed right before the user’s profile script. The user’s ~/.bash_profile script, if it exists, is the next script that’s sourced. This file contains variables, code, and settings that directly affect that user’s—and only that user’s—environment. This script calls, or sources, the next script, which is .bashrc.
The .bash_profile script can also be referred to or named as the .bash_login or .profile script. If all three exist, the .bash_profile is sourced alone; otherwise, if it doesn’t exist, the .bash_login is sourced. Finally, if the first two are nonexistent, the .profile script is sourced. This functionality is used almost entirely by Bourne shell users upgrading to a bash system as a way to keep their settings in the same .profile file.
The .bashrc file is called by the .bash_profile or one of the profile’s aliases and is used to set various shell settings and options, set the prompt, and define aliases and functions for command-line execution. The last script sourced during a user’s login session is the .bash_logout file. This file is used to issue the clear command, so text from any previous command is not left on the user’s screen after he logs out.
TIP: Be careful on the exam because a lot of test-takers do not pick the .bash_logout file as part of the user’s login session. It’s definitely one of the more missed elements in the shell section.
An example of the user’s login session might be the following:
1. The user logs in with a username and password.
2. The /etc/profile is sourced.
3. The user’s .bash_profile is sourced.
4. The user’s .bashrc is sourced from within the .bash_profile.
5. The user conducts his business.
6. The user initiates a logout with the logout or exit command or by
pressing Ctrl+D.
7. The user’s .bash_logout script is sourced.
Summary
Remember these important things: 1. Executing a script file only loads the settings contained in it within the life of the sub-shell the script executes in, they are gone when the sub-shell exits. 2. Sourcing a script file ( preceeding it with dot, such as ” . /etc/bashrc” will load the variables and settings in that file into the current shell.
For more information on how to use the shell, you can turn to many multiple resources, including Chapter 2 of the current version of my LPIC 1 Exam Cram 2 book (look for it in the sidebar ->), starting on Pg 28, the second would be the bash shell’s man page (man bash), still another would be the Guides section of The Linux Document Project’s site, particularly the Bash Guide for Beginners.
Any comments, suggestions or questions are welcome.
RossB
Copyright 2000-2009 Ross Brunson





















