-->
Previous Table of Contents Next


Chapter 6
Linux Shells

You can’t run Linux without running a shell, a tool that interacts with you and provides a way to directly communicate with the core of the operating system. What you assume is being done by the operating system is most often being done by the shell: It accepts your commands, interprets them, and passes them along to the core operating system; it provides its own set of commands (some of which were covered in Chapter 5 as operating-system commands; it’s really a distinction without difference); and it provides its own scripting mechanisms.

Most Linux distributions include at least six or seven shells, but people usually stick with the default Bourne Again Shell (bash) from the Free Software Foundation, a clone of the popular Bourne shell found on most UNIX systems. In addition, many users switch to the C shell (csh) or a scaled-down version of the C shell, tcsh. (When you install your Linux distribution, you’re typically asked which shells you want installed on your system. A slew of Linux shellsare available, including ash and zsh.) To see which shells are installed on your system, use the following command line:


$ chsh -l

/bin/sh

/bin/bash

/bin/csh

/bin/tcsh

...

To change your login shell, use one of the following command lines:


$ chsh -s /bin/csh

or


$ exec /bin/csh

We’re not going to spend a lot of time on shells; there’s more than enough online documentation for them, and there are more than enough books on the market about shells and their usage. Instead, we’ll spend some time covering shell variables.

Shell Variables

These variables are set by the shell. They are used in a wide variety of circumstances, but typically they’re involved in shell scripts.

Variable Explanation
IFS The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read built-in command. The default value is space-tab-newline’.
PATH The search path for commands. It is a colon-separated list of directories in which the shell looks for commands. The default path is system-dependent and is set by the administrator who installs bash.
HOME The home directory of the current user; the default argument for the cd command.
CDPATH The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command.
ENV If this parameter is set when bash is executing a shell script, its value is interpreted as a filename containing commands to initialize the shell, as in .bashrc. The value of ENV is subjected to parameter expansion, command substitution, and arithmetic expansion before being interpreted as a pathname. PATH is not used to search for the resultant pathname.
MAIL If this parameter is set to a filename and the MAILPATH variable is not set, bash informs the user of the arrival of mail in the specified file.
MAILCHECK Specifies how often (in seconds) bash checks for mail. The default is 60 seconds. When it is time to check for mail, the shell does so before prompting. If this variable is not set, the shell disables mail checking.
MAILPATH A colon-separated list of pathnames to be checked for mail. The message to be printed may be specified by separating the pathname from the message with ?.
MAIL_WARNING If set, and a file that bash is checking for mail has been accessed
since the last time it was checked, the message The mail in mailfile has been read is printed.
PS1 Sets the primary prompt. The default value is bash\$.
PS2 Sets the secondary prompt, used by many applications to provide input. The default value is >.
PS3 Set the prompt for the select command.
PS4 Sets the value of the character used before commands in an execution trace. The default is +.
HISTSIZE Sets the number of commands to remember in the command history. The default is 500.
HISTFILE Sets the name of the file where command history is saved. The default is [sim]/.bash_history.
HISTFILESIZE Sets the maximum number of lines in the history file. The default value is 500.
IGNOREEOF Controls the action of the shell on receipt of an EOF character as the sole input. If set, the value is the number of consecutive EOF characters typed as the first characters on an input line before bash exits. If the variable exists but does not have a numeric value,or has no value, the default value is 10. If it does not exist, EOF signifies the end of input to the shell. This is only in effect for interactive shells.
TMOUT If set to a value greater than zero, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt. bash terminates after waiting for that number of seconds if input does not arrive.
FIGNORE A colon-separated list of suffixes to ignore when performing filename completion. A filename whose suffix matches one of the entries in FIGNORE is excluded from the list of matched filenames. A sample value is ``.o:[sim]’’.


Previous Table of Contents Next