6

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?

10

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.

  • It's probably not listed as an option for set as one cannot set -i to make an already running shell interactive (bash complains with "invalid option"). – Kusalananda May 12 '17 at 10:54
  • @Kusalananda yes, that’s what I thought too. – Stephen Kitt May 12 '17 at 10:57
  • what is it good for to type set +i in order to switch the i flag off? – sharkant May 12 '17 at 10:58
  • 1
    @sharkant One may test on $- to determine if the current shell is interactive or not. This may be useful in shell initialisation scripts. Actually setting this makes no sense as it is determined by the parent process whether it's interactive or not. – Kusalananda May 12 '17 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.