我们如何获取 set -o ... 中没有直接别名的标志的状态
set [-+]
,例如
set -o posix
或者
set -o vi
?
不是,例如,set -o errexit
可以set [-+] e
通过以下方式检索
$ echo $-
然后会判断输出字符串中是否存在字母e。请真心帮忙。
答案1
您可以使用set -o
而不带参数:
$ set -o
allexport off
braceexpand on
emacs off
errexit off
errtrace off
functrace off
hashall on
histexpand on
history on
ignoreeof off
interactive-comments on
keyword off
monitor on
noclobber off
noexec off
noglob off
nolog off
notify off
nounset off
onecmd off
physical off
pipefail off
posix off
privileged off
verbose off
vi on
xtrace off
或者看看炮弹多变的:
$ echo "$SHELLOPTS"
braceexpand:hashall:histexpand:history:interactive-comments:monitor:vi
答案2
和bash
:
if shopt -qpo posix; then
echo "turned on";
else
echo "turned off";
fi
请参阅:help set
和help shopt