Classic Shell Scripting - Arnold Robbins [205]
histverify
With readline, bash loads the result of a history substitution into the editing buffer for further changing.
hostcomplete
bash performs hostname completion with readline on words containing an @ character. This is on by default.
huponexit
bash sends SIGHUP to all jobs when an interactive login shell exits.
interactive_comments
bash treats # as starting a comment for interactive shells. This is on by default.
lithist
When used together with the cmdhist option, bash saves multiline commands in the history with embedded newlines, rather than semicolons.
login_shell
bash sets this option when it is started as a login shell. It cannot be changed.
mailwarn
bash prints the message "The mail in mailfile has been read" when the access time has changed on a file that bash is checking for mail.
no_empty_cmd_completion
bash does not search $PATH when command completion is attempted on an empty line.
nocaseglob
bash ignores case when doing filename matching.
nullglob
bash causes patterns that don't match any files to become the null string, instead of standing for themselves. This null string is then removed from further command-line processing; in effect, a pattern that doesn't match anything disappears from the command line.
progcomp
This option enables the programmable completion features. See the bash(1) manpage for details. It is on by default.
promptvars
bash performs variable and parameter expansion on the value of the various prompt strings. This is on by default.
restricted_shell
bash sets this to true when functioning as a restricted shell. This option cannot be changed. Startup files can query this option to decide how to behave. See Section 15.2, for more information on restricted shells.
shift_verbose
bash prints a message if the count for a shift command is more than the number of positional parameters left.
sourcepath
bash uses $PATH to find files for the source and . (dot) commands. This is on by default. If turned off, you must use a full or relative pathname to find the file.
xpg_echo
bash's built-in echo processes backslash escape sequences.
Common Extensions
Both bash and ksh93 support a large number of extensions over the POSIX shell. This section deals with those extensions that overlap; i.e., where both shells provide the same features, and in the same way.
The select Loop
bash and ksh share the select loop, which allows you to generate simple menus easily. It has concise syntax, but it does quite a lot of work. The syntax is:
select name [in list]
do
statements that can use $name ...
done
This is the same syntax as the regular for loop except for the keyword select. And like for, you can omit the in list and it will default to "$@"; i.e., the list of quoted command-line arguments.
Here is what select does:
Generate a menu of each item in list, formatted with numbers for each choice
Print the value of PS3 as a prompt and waits for the user to enter a number
Store the selected choice in the variable name and the selected number in the built-in variable REPLY
Execute the statements in the body
Repeat the process forever (but see later for how to exit)
An example should help make this process clearer. Suppose you need to know how to set the TERM variable correctly for a timesharing system using different kinds of video display terminals. You don't have terminals hardwired to your computer; instead, your users communicate through a terminal server. Although the telnet protocol can pass the TERM environment variable, the terminal server isn't smart enough to do so. This means, among other things, that the tty (serial device) number does not determine the type of terminal.
Therefore, you have no choice but to prompt the user for a terminal type at login time. To do this, you can put the following code in /etc/profile (assume you have a fixed set of known terminal types):
PS3='terminal? '
select term in gl35a t2000 s531 vt99
do
if [ -n "$term"