1317

7 分钟

#Bash 的 shopt 命令

shopt [OPTION]... [OPT_NAME]...

功能

设置和取消设置 shell 选项。

类型

Bash 内置命令。

参数

  • OPTION - 选项:
    • -o - 限制只能操作 set -o 定义的选项
    • -p - 以命令行的格式打印每个 shell 选项及其状态
    • -q - 不打印输出
    • -s - 开启选项
    • -u - 关闭选项
  • N - shell 的返回值为 N;如果省略此参数,则以最后一个命令的返回值作为 shell 的返回值

#示例

查看选项

$ shopt
autocd         	    off
assoc_expand_once	off
cdable_vars    	    off
cdspell        	    off
...

开启和关闭选项

$ shopt -s autocd   # 开启 autocd
$ shopt -u autocd   # 关闭 autocd

#手册

更新: 2026/4/24

作者: PlanC

创建: 2026/4/24