Bash – the parameter “i” of the set command in the bash shell

bashsetshell-builtin

I looked up the shell builtin command set by typing help set, and the short syntax description shows:

set [-abefhkmnptuvxBCHP] [-o option-name] [–] [arg …]

The help-documentation explains, that the variable $- holds all current parameters set with the set command.

So, I did echo $- to display all parameter settings of the shell and mine was:

himBH

All of the letters are mentioned inside the documentation and the short syntax description from above, but one is missing: the i option. What does the i set parameter mean in bash?

Best Answer

The i there means the shell is interactive.

This is described in the manpage section discussing the circumstances in which the shell is interactive:

An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)), or one started with the -i option. PS1 is set and $- includes i if bash is interactive, allowing a shell script or a startup file to test this state.

The interactive nature of the shell is determined during initialisation, and its effects don’t change during the shell’s lifetime; this is why set doesn’t report i as a flag that can be altered. In version 4.3 of Bash, set -i or set +i are accepted, but don’t have any effect beyond altering the forced_interactive flag internally (and this flag is only read during initialisation). In version 4.4 they produce an error message. You can see the details of flag handling in flags.c in the Bash source code.