bash:从set中查找值

时间:2014-04-02 16:28:25

标签: bash

我可以使用set命令来更改bash shell选项,例如:

set -ex

是否有命令检查是否已设置-e-x选项?

3 个答案:

答案 0 :(得分:5)

短信息中的$-,您可以查看$SHELLOPTS以逗号分隔的选项列表。

echo $SHELLOPTS
braceexpand:hashall:histexpand:history:interactive-comments:monitor:vi

set -x
echo $SHELLOPTS
braceexpand:hashall:histexpand:history:interactive-comments:monitor:vi:xtrace
                                                                       ^^^^^^
set +x
set -v
echo $SHELLOPTS
braceexpand:hashall:histexpand:history:interactive-comments:monitor:verbose:vi
                                                                    ^^^^^^^

等...

列表,请检查:https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html

答案 1 :(得分:2)

来自man bash:“当前的选项集可以在$ - ”中找到,所以请使用

echo $-

答案 2 :(得分:2)

变量$-包含所有shell选项:

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