Chapter 6: Bash Features

84

An interactive shell generally reads from and writes to a user’s terminal.

The -s invocation option may be used to set the positional parameters when an inter- active shell is started.

6.3.2 Is this Shell Interactive?

To determine within a startup script whether or not Bash is running interactively, test the value of the ‘-’ special parameter. It contains i when the shell is interactive. For example: case "$-" in

*i*) echo This shell is interactive ;;

*) echo This shell is not interactive ;; esac

Alternatively, startup scripts may examine the variable PS1; it is unset in non-interactive shells, and set in interactive shells. Thus: if [ -z "$PS1" ]; then echo This shell is not interactive else echo This shell is interactive fi

6.3.3 Interactive Shell Behavior

When the shell is running interactively, it changes its behavior in several ways.

1. Startup files are read and executed as described in Section 6.2 [Bash Startup Files], page 82.

2. Job Control (see Chapter 7 [Job Control], page 97) is enabled by default. When job control is in effect, Bash ignores the keyboard-generated job control signals SIGTTIN,

SIGTTOU, and SIGTSTP.

3. Bash expands and displays PS1 before reading the first line of a command, and ex- pands and displays PS2 before reading the second and subsequent lines of a multi-line command.

4. Bash executes the value of the PROMPT_COMMAND variable as a command before printing the primary prompt, $PS1 (see Section 5.2 [Bash Variables], page 69).

5. Readline (see Chapter 8 [Command Line Editing], page 101) is used to read commands from the user’s terminal.

6. Bash inspects the value of the ignoreeof option to set -o instead of exiting imme- diately when it receives an EOF on its standard input when reading a command (see

Section 4.3.1 [The Set Builtin], page 58).

7. Command history (see Section 9.1 [Bash History Facilities], page 133) and history expansion (see Section 9.3 [History Interaction], page 135) are enabled by default.

Bash will save the command history to the file named by $HISTFILE when a shell with history enabled exits.

8. Alias expansion (see Section 6.6 [Aliases], page 88) is performed by default.

9. In the absence of any traps, Bash ignores SIGTERM (see Section 3.7.6 [Signals], page 38).

10. In the absence of any traps, SIGINT is caught and handled ((see Section 3.7.6 [Signals], page 38). SIGINT will interrupt some shell builtins.