Linux Know-How provides a collection of introductory texts on often needed Linux skills.


Interactive shells

What is an interactive shell?

An interactive shell generally reads from, and writes to, a user's terminal: input and output are connected to a terminal. Bash interactive behavior is started when the bash command is called upon without non-option arguments, except when the option is a string to read from or when the shell is invoked to read from standard input, which allows for positional parameters to be set (see Chapter 3 ).

Is this shell interactive?

Test by looking at the content of the special parameter -, it contains an 'i' when the shell is interactive:

eddy:~> echo $-
himBH

In non-interactive shells, the prompt, PS1, is unset.

Interactive shell behavior

Differences in interactive mode:

  • Bash reads startup files.

  • Job control enabled by default.

  • Prompts are set, PS2 is enabled for multi-line commands, it is usually set to ">". This is also the prompt you get when the shell thinks you entered an unfinished command, for instance when you forget quotes, command structures that cannot be left out, etc.

  • Commands are by default read from the command line using readline.

  • Bash interprets the shell option ignoreeof instead of exiting immediately upon receiving EOF (End Of File).

  • Command history and history expansion are enabled by default. History is saved in the file pointed to by HISTFILE when the shell exits. By default, HISTFILE points to ~/.bash_history.

  • Alias expansion is enabled.

  • In the absence of traps, the SIGTERM signal is ignored.

  • In the absence of traps, SIGINT is caught and handled. Thus, typing Ctrl+C, for example, will not quit your interactive shell.

  • Sending SIGHUP signals to all jobs on exit is configured with the huponexit option.

  • Commands are executed upon read.

  • Bash checks for mail periodically.

  • Bash can be configured to exit when it encounters unreferenced variables. In interactive mode this behavior is disabled.

  • When shell built-in commands encounter redirection errors, this will not cause the shell to exit.

  • Special built-ins returning errors when used in POSIX mode don't cause the shell to exit. The built-in commands are listed in Section 1.3.

  • Failure of exec will not exit the shell.

  • Parser syntax errors don't cause the shell to exit.

  • Simple spell check for the arguments to the cd built-in is enabled by default.

  • Automatic exit after the length of time specified in the TMOUT variable has passed, is enabled.

More information:


Last Update: 2010-12-16