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

I have looked at some of the .bashrc and .profile scripts that come with various Linux distributions, and I see that sometimes they check $- .

Here is one in Ubuntu

 case $- in *i*) ;; *) return;; esac 

In this case, it checks for the presence of the "i" flag to see if the current shell is interactive.

My current session gives me the following:

 # echo $- himBH 

What do other flags / options mean? Is there an exhaustive list somewhere?

+4
source share
2 answers

From man bash :

-

Expands to the current option flags specified during the call, with the set builtin command or those set by the shell itself (for example, the -i option).

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

+9
source

They mean different things. Each letter corresponds to the option given for bash. for example, β€œi” means that the shell is interactive (so the sample code you gave is a test to see if it is an interactive shell or not).

A complete list is available on the bash manual page. Look for "set" - here is the first line:

 set [+abefhkmnptuvxBCEHPT] [+o option-name] [arg ...] 
0
source

Source: https://habr.com/ru/post/1496137/


All Articles