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

后端 未结 2 878
野的像风
野的像风 2021-01-02 07:09

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 $-.

Her

相关标签:
2条回答
  • 2021-01-02 07:39

    They mean various things. Each letter corresponds to an option being set for bash. eg, "i" means that the shell is interactive (so the code sample you gave is a test to see if it's an interactive shell or not).

    A full list is available in the bash man page. Look for "set" - here's the first line:

    set [+abefhkmnptuvxBCEHPT] [+o option-name] [arg ...]
    
    0 讨论(0)
  • 2021-01-02 07:51

    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
    0 讨论(0)
提交回复
热议问题