-->

Previous | Table of Contents | Next

Page 26

replacing the old. The environment inherited by any executed command consists of the shell's initial environment, whose values may be modified in the shell, less any pairs removed by the unset command, plus any additions via the export and declare _x commands.

The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described earlier in "Parameters." These assignment statements affect only the environment seen by that command.

If the _k flag is set (see the set built-in command), then all parameter assignments are placed in the environment for a command, not just those that precede the command name.

When bash invokes an external command, the variable is set to the full path name of the command and passed to that command in its environment.

EXIT STATUS

For the purposes of the shell, a command which exits with a zero exit status has succeeded. An exit status of zero indicates success. A non_zero exit status indicates failure. When a command terminates on a fatal signal, bash uses the value of 128+signal as the exit status.

If a command is not found, the child process created to execute it returns a status of 127. If a command is found but is not executable, the return status is 126.

bash itself returns the exit status of the last command executed, unless a syntax error occurs, in which case it exits with a non_zero value. (See also the exit built-in command.)

PROMPTING

When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:

\t The current time in HH:MM:SS format
\d The date in "Weekday Month Date" format (for example, "Tue May 26")
\n Newline
\s The name of the shell, the basename of $0 (the portion following the final slash)
\w The current working directory
\W The basename of the current working directory
\u The username of the current user
\h The hostname
\# The command number of this command
\! The history number of this command
\$ If the effective UID is 0, a #, otherwise a $
\nnn The character corresponding to the octal number nnn
\\ A backslash
\[ Begin a sequence of nonprinting characters, which could be used to embed a terminal control sequence into the prompt
\] End a sequence of nonprinting characters

The command number and the history number are usually different: the history number of a command is its position in the history list, which may include commands restored from the history file (see "History," later in this manual page), while the command number is the position in the sequence of commands executed during the current shell session. After the string is decoded, it is expanded via parameter expansion, command substitution, arithmetic expansion, and word splitting.

Page 27

READLINE

This is the library that handles reading input when using an interactive shell, unless the _nolineediting option is given. By default, the line editing commands are similar to those of emacs. A vi-style line editing interface is also available.

In this section, the emacs-style notation is used to denote keystrokes. Control keys are denoted by C_key; for example, C_n means Ctrl_N. Similarly, meta keys are denoted by M_key, so M_x means Meta_X. (On keyboards without a meta key, M_x means Esc-X; that is, press the Escape key, then the X key. This makes ESC the meta prefix. The combination M_C_x means Esc_Control_x, or press the Escape key then hold the Control key while pressing the X key.)

The default key-bindings may be changed with a /.inputrc file. The value of the shell variable INPUTRC, if set, is used instead of ~/.inputrc. Other programs that use this library may add their own commands and bindings.

For example, placing


M_Control_u: universal_argument

or


C_Meta_u: universal_argument

into the /.inputrc would make M_C_u execute the readline command universal_argument.The following symbolic character names are recognized: RUBOUT, DEL, ESC, LFD, NEWLINE, RET, RETURN, SPC, SPACE, and TAB. In addition to command names, readline allows keys to be bound to a string that is inserted when the key is pressed (a macro).

Readline is customized by putting commands in an initialization file. The name of this file is taken from the value of the INPUTRC variable. If that variable is unset, the default is ~/.inputrc. When a program that uses the readline library starts up, the init file is read, and the key bindings and variables are set. There are only a few basic constructs allowed in the readline init file. Blank lines are ignored. Lines beginning with a # are comments. Lines beginning with a $ indicate conditional constructs. Other lines denote key bindings and variable settings.

The syntax for controlling key bindings in the ~/.inputrc file is simple. All that is required is the name of the command or the text of a macro and a key sequence to which it should be bound. The name may be specified in one of two ways: as a symbolic key name, possibly with Meta- or Control- prefixes, or as a key sequence. When using the form keyname:function-name or macro, keyname is the name of a key spelled out in English. For example,


Control-u: universal_argument

Meta-Rubout: backward-kill-word

Control-o: ">&output"

In the preceding example, C-u is bound to the function universal_argument, M-DEL is bound to the function backward_kill_word,and C-o is bound to run the macro expressed on the righthand side (that is, to insert the text >&output into the line).

In the second form, "keyseq":function-name or macro, keyseq differs from keyname in that strings denoting an entire key sequence may be specified by placing the sequence within double quotes. Some GNU emacs-style key escapes can be used, as in the following example:


"\C-u": universal_argument

"\C-x\C-r": re_read_init_file

"\e[11~": "Function Key 1"

In this example, C-u is again bound to the function universal_argument. C-x C-r is bound to the function re_read_init_file, and ESC[11~ is bound to insert the text Function Key 1. The full set of escape sequences is

\C_ Control prefix
\M- Meta prefix
\e An escape character
\\ Backslash
\" Literal "
\' Literal `

Previous | Table of Contents | Next