What do the characters in the bash environment variable $- mean?

bash, linux

Solution

From man bash:

Expands to the current option flags as specified upon invocation, by the set builtin command, or those set by the shell itself (such as the -i option).

So these are the current options that control the behavior of the shell. In particular:

- `h`: Cache location of binaries in the `$PATH`. Speeds up execution, but fails if you move binaries around during the shell session.

- `i`: The current shell is interactive

- `m`: Job control is enabled

- `B`: Brace expansion is enabled

- `H`: History substitution like `!-1`

Problem

I've been looking through some of the .bashrc and .profile scripts that come with various Linux distros and am seeing that sometimes they check `$-`. Here's one in Ubuntu ``` case $- in *i*) ;; *) return;; esac ``` In this case it's checking for the "i" flag is present to see if the current shell is an interactive one. My current session gives me this : ``` # echo $- himBH ``` What are the other flags/options mean? Is there a comprehensive list somewhere?

Original source