Donation?

Harley Hahn
Home Page

Send a Message
to Harley


A Personal Note
from Harley Hahn

Unix Book
Home Page

SEARCH

List of Chapters

Table of Contents

List of Figures

Chapters...
   1   2   3
   4   5   6
   7   8   9
  10  11  12
  13  14  15
  16  17  18
  19  20  21
  22  23  24
  25  26

Glossary

Appendixes...
  A  B  C
  D  E  F
  G  H

Command
Summary...

• Alphabetical
• By category

Unix-Linux
Timeline

Internet
Resources

Errors and
Corrections

Endorsements


INSTRUCTOR
AND STUDENT
MATERIAL...

Home Page
& Overview

Exercises
& Answers

The Unix Model
Curriculum &
Course Outlines

PowerPoint Files
for Teachers

Appendix G...

Shell Options & Shell Variables

Every shell supports a variety of ways for you to control its behavior. The Bourne Shell family (Bash, Korn Shell) uses shell options; the C-Shell family (Tcsh, C-Shell) uses both shell options and shell variables. This appendix summarizes these options and variables.

For a detailed discussion of both shell options and shell variables, see Chapter 12.

Bourne Shell Family

The Bourne Shell family uses a large number of options to control the behavior of the shell. In particular, interactive shells require different options than non-interactive shells. (In fact, this is what makes them interactive.)

There are two ways to specify such options. First, they may be invoked in the standard manner by specifying options on the command line when the shell is started. This is the case for non-interactive shells that are run automatically, and for interactive shells that you yourself start by entering a command. For example:

bash -vx

(By the way, these two options are particularly useful when you are testing or debugging a shell script.)

Within an interactive shell — that is, at the shell prompt — you can turn options on or off as you wish. To set (turn on) an option, use the set ‑o command. To unset (turn off) an option, use the set  +o command. When you use these commands, you specify the long name for the option, not its abbreviation. For example:

set -o verbose
set +o xtrace

To display the current state of all the options, use either command by itself:

set -o
set +o

The -o variation prints human-readable output; +o prints output suitable for a script. (Try them.)

In all, the Bourne Shell family uses a great many shell options. In most cases, you will not need to change them, because the defaults will work just fine. For reference, however, the table in Figure G-1 summarizes the shell options for Bash and the Korn Shell. Not all options are available with all shells, so be sure to look at the leftmost column, which shows you which shells support each option.

— hint —

With Bash, there are extra options available to control a variety of features. To set and unset these options, you use the shopt ("shell options") command. The shopt options are so esoteric that you are unlikely to need them. If you have a moment, though, and you'd like to take a look at them, see the shopt man page.

If you have a moment, though, and you'd like to take a look at them, the best place to read about the shopt options is the Bash man page. To find the relevant discussion, search for "shopt".

Figure G-1:  Bourne Shell family: Shell options

This table summarizes the important shell options available with Bourne family shells. The leftmost column shows which shells support each option: B = Bash; K = Korn Shell. A dot indicates that a shell does not support that option. Note that some options, such as bgnice, have a long name but not a short option name. For more information, see the man page for your particular shell.

Notes: (1) Although Bash supports the emacs and vi options, it does not use -E and -V. (2) The Korn shell uses -h and -t, but does not support the long names hashall and onecmd.

Shells Option Long Name Meaning
B K -aallexportexport all subsequently defined variables and functions
• K bgnicerun background jobs at lower priority
B •-Bbraceexpandbrace expansion: enable
B K -cread commands from string argument
B K -Eemacscommand line editor: Emacs mode; turns off vi mode
B K -eerrexitif a command fails, abort and exit script
B K -hhashallhash (remember) locations of commands as they are found
B •-Hhistexpandcommand history: enable ! style history substitution
B • historycommand history: enable
B K -Iignoreeofignore eof signal ^D; use exit to quit shell (see Chapter 7)
B K -kkeywordplace all keyword arguments in the environment
• K markdirswhen globbing, append / to directory names
B K -mmonitorjob control: enable
B K -Cnoclobberdo not allow redirected output to replace a file
B K -nnoexecdebug: read commands, check syntax, but do not execute
B K -fnoglobglobbing (filename expansion): disable
• K nologdo not save function definitions in history file
B K -bnotifyjob control: notify immediately when background jobs finish
B K -unounsettreat using an unset variable as an error
B K -tonecmdread and execute one command, then exit
B • posixconform to POSIX standard
B •-pprivilegeduse privileged mode to run a script or start a shell
B •-rstart shell in restricted mode
• K-ssort positional parameters
• K trackallaliases: substitute full pathnames for commands
B K -vverbosedebug: echo each command to stderr (standard error)
B K -Vvicommand line editor: vi mode; turns off Emacs mode
• K virawin vi mode: process each character as it is typed
B K -xxtracedebug: as command executes, echo to stderr (that is, trace)
Shells Option Long Name Meaning

Jump to top of page

C-Shell Family

The C-Shell family also uses options to control the behavior of the shell. These options are summarized in Figure G-2. If you compare the options in Figure G-2 with those in Figure G-1, you will notice that most of the C-Shell options are also used by the Bourne Shell family. However, there is an important difference.

In the Bourne Shell family the behavior of the shell is controlled entirely by options, of which there are three types: regular command-line options (such as -v), "long name" options used with the set  +o command, and the large number of extra options used only with the Bash shopt command.

Although the C-Shell family does use a small number of command-line options (Figure  G-2), for the most part, the behavior of a shell is controlled by shell variables. This is one of the important differences between C-Shell family and the Bourne Shell family, and is explained in detail in Chapter 12. For reference, Figure G-3 contains a summary of the shell variables used by the C-Shell and Tcsh.

Figure G-2:  C-Shell family: Shell options

This table summarizes the important shell options available with C-Shell family. The leftmost column shows which shells support each option: C = C-Shell; T = Tcsh. A dot indicates that a shell does not support that option. For more information, see the man page for your particular shell.

Note: The -v and -V options work by setting the verbose shell variable. The -x and -X options work by setting the echo shell variable.

Shells Option Shell Variable Meaning
C T-cread commands from string argument; compare to -s
• T-dload directory stack from .cshdirs file
C T-eif a command fails, abort and exit script
C T-iinteractive mode (affects prompts, error handling, etc.)
C T-ndebug: read commands, check syntax, but do not execute
C T-sread commands from stdin (standard input); compare to -c
C T-tread and execute one command, then exit
C T-vverbosedebug: echo each command, after history substitution only
C T-Vverbosedebug: set verbose before reading .tcshc/.cshrc file
C T-xechodebug: echo each command, after all substitutions
C T-Xechodebug: set echo before reading .tcshc/.cshrc file

Figure G-3:  C-Shell family: Shell variables

This table summarizes the important shell variables used with the C-Shell family to control the behavior of the shell. The leftmost column shows which shells support each option: C = C-Shell; T = Tcsh. A dot indicates that a shell does not support that option.

For more information, see the man page for your shell. For information about autocompletion, spell-correction, or command line editing, see the Tcsh man page. For a detailed discussion of shell variables, see Chapter 12.

Shells Shell Variable Meaning
• Taddsuffixautocomplete: append / (slash) after directory names
• Tampmshow times in 12-hour AM/PM format
• Tautocorrectspell-correct: invoke spell-word editor before completion attempt
• Tautoexpandautocomplete: invoke expand-history editor before completion attempt
• Tautolistautocomplete: when completion fails, list remaining choices
• Tautologouttime (in minutes) until auto-logout, if you don't type a command
C Tcdpathdirectories to be searched by cd, chdir, popd
• Tcolorcause ls-F command to use color
• Tcompleteautocomplete: igncase=ignore case; enhance=also . - _ are separators
• Tcorrectspell-correct: cmd=command; all=entire line; complete=complete instead
C Tcwdyour current working directory (compare to owd)
C Techodebug: echo each command, after all substitutions
• Techo_styleecho command: bsd (support -n); sysv (support \ escape); both; none
• Teditcommand line editor: enable
C Tfignoreautocomplete: suffixes to ignore
C •filecautocomplete: enable (always on with Tcsh)
• Tgroupcurrent groupid
C Thardpathsdirectory stack: resolve pathnames to contain no symbolic links
C Thistorycommand history: number of lines in history list
C Thomeyour home directory
C Tignoreeofdo not quit shell upon eof signal (^D)
• Timplicitcdtyping directory name by itself means change to that directory
• Tinputmodecommand line editor: set initial mode at start of line, insert or overwrite
• Tlistjobsjob control: list all jobs whenever a job is suspended; long = long format
• Tloginshset to indicate a login shell
C Tmaillist of files to check for new email
• Tmatchbeepautocomplete: make a sound; ambiguous, notunique, never, nomatch
C Tnobeepautocomplete: never make a sound
C Tnoclobberdo not allow redirected output to replace a file
C Tnoglobglobbing (filename expansion): disable
C Tnotifyjob control: notify immediately when background jobs finished
• Towdyour most recent [old] working directory (compare to cwd)
C Tpathdirectories to search for programs
C Tpromptyour shell prompt (customize by changing this variable)
• Tpushdsilentdirectory stack: pushd and popd do not list directory stack
• Tpushdtohomedirectory stack: pushd without arguments assumes home directory (like cd)
• Trecexactautocomplete: match exact match even if longer match is possible
• Trmstarforce user to confirm before executing rm * (remove all files)
• Trpromptwhen prompting, string to print on right side of screen (hint: set to %/)
• Tsavedirsdirectory stack: before logout, save directory stack
C Tsavehistcommand history: before logout, save this number of lines in history list
C Tshellpathname of your login shell
C Ttermtype of terminal you are using
C Tusercurrent userid
C Tverbosedebug: echo each command, after history substitution only
• Tvisiblebelluse a screen flash instead of an audible sound
Shells Shell Variable Meaning

Jump to top of page