Answers:
赶紧跑:
$ shopt extglob
它将返回当前状态:
$ shopt extglob
extglob on
$ shopt -u extglob
$ shopt extglob
extglob off
要显示所有选项,只需运行:
$ shopt
使用shopt -q:
shopt -q extglob && echo enable || echo disable
-q
option shopt
放弃输出,并返回状态以指示选项已设置或未设置。
请注意,shopt
仅报告可以在BASHOPTS
变量中显示的选项,这些选项对set
内置命令无效。
要检查对set
或有效的选项SHELLOPTS
,请使用shopt -qo
:
$ bash --posix -c 'shopt -qo posix && echo enable || echo disable'
enable
shopt extglob
呢?
shopt extglob
和您的方法都将写入stdout。你在想shopt -q extglob && shopt -u extglob || shopt -s extglob
什么?
shopt -q extglob && : Code when enable || : Code when disable
。
bash中有两个选项列表。一为shopt
一set
。
该选项extglob
属于shopt
列表。
可以使用shopt extglob
或来打印其值shopt -p extglob
。
像这样的选项nounset
属于该set
列表。
其值可以使用shopt -op nounset
或打印shopt -o nounset
。
要为购物者打印特定选项(无需更改),请使用shopt -p name
:
$ shopt -p xpg_echo
shopt -u xpg_echo
对于set
,请使用:(shopt -po name
是的,您可以将其shopt -op
用于set
列表)。
$ shopt -po xtrace
set +o xtrace
要列出购物商店中的所有选项,请使用shopt
(或可重用shopt -p
)。
此外shopt -s
或者shopt -u
也可以使用。
列出所有选项的方法set
是set -o
(相关:)set +o
。
或者:shopt -o
相当于set -o
和shopt -op
是set +o
。
来自LESS=+/'^ *shopt \[' man bash
:
如果不使用任何选项,或者使用-p选项,则显示所有可设置选项的列表。如果不使用optname参数使用-s或-u,则显示分别限于设置或未设置的那些选项。
来自LESS=+/'^ *set \[' man bash
:
如果提供的-o没有选项名,则打印当前选项的值。如果提供的+ o没有选项名称,则在标准输出上显示一系列用于重新创建当前选项设置的set命令。
$ set -o
allexport off
braceexpand on
emacs on
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 off
xtrace off
和
$ shopt -sp
shopt -s checkwinsize
shopt -s cmdhist
shopt -s expand_aliases
shopt -s extglob
shopt -s extquote
shopt -s force_fignore
shopt -s histappend
shopt -s histverify
shopt -s interactive_comments
shopt -s progcomp
shopt -s promptvars
shopt -s sourcepath
值得一提的是shopt -op
哪些实际上列出了set
选项:
$ shopt -op
set +o allexport
set -o braceexpand
set -o emacs
set +o errexit
set +o errtrace
set +o functrace
set -o hashall
set -o histexpand
set -o history
set +o ignoreeof
set -o interactive-comments
set +o keyword
set -o monitor
set +o noclobber
set +o noexec
set +o noglob
set +o nolog
set +o notify
set +o nounset
set +o onecmd
set +o physical
set +o pipefail
set +o posix
set +o privileged
set +o verbose
set +o vi
set +o xtrace
shopt -s extglob
,如果要关闭,请运行shopt -u extglob
。不论是否原始,它都没有任何区别。