小智 8
bash 中有两个选项列表。一为shopt
一为set
。
要为 shopt 打印特定选项(不更改它),请使用shopt -p name
:
$ shopt -p xpg_echo
shopt -u xpg_echo
Run Code Online (Sandbox Code Playgroud)
而对于set
,使用:shopt -po name
(是的,你可以使用shopt -op
的set
列表)。
$ shopt -po xtrace
set +o xtrace
Run Code Online (Sandbox Code Playgroud)
要列出 shopt 中的所有选项,请使用shopt
(或 reusable shopt -p
)。
此外shopt -s
或者shopt -u
也可以使用。
列出所有选项的方法set
是使用set -o
(related: set +o
)。
或:shopt -o
相当于set -o
并且shopt -op
是set +o
。
来自LESS=+/'^ *shopt \[' man bash
:
不带选项或带 -p 选项时,将显示所有可设置选项的列表。如果使用 -s 或 -u 且不带 optname 参数,则显示分别限于已设置或未设置的选项。
来自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
Run Code Online (Sandbox Code Playgroud)
和
$ 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
Run Code Online (Sandbox Code Playgroud)
值得一提的是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
Run Code Online (Sandbox Code Playgroud)