Linux command
shopt 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
List all shell options
shopt
Enable a shell option
shopt -s [optname]
Disable a shell option
shopt -u [optname]
Check if an option is set
shopt -q [optname] && echo "enabled"
Enable extended globbing
shopt -s extglob
Enable case-insensitive globbing
shopt -s nocaseglob
Include dotfiles in glob patterns
shopt -s dotglob
Print options in reusable format
shopt -p
说明
shopt is a Bash builtin that enables or disables shell options for the current session. These options modify shell behavior including globbing, history handling, directory navigation, and command completion. Without arguments, shopt lists all options and their current status. Use -s to enable and -u to disable specific options. The -q flag tests options silently, setting exit status 0 if enabled, 1 if disabled. Options set with shopt persist only for the current session. Add shopt commands to ~/.bashrc for permanent configuration.
参数
- -p
- Print shell options in a format reusable as input
- -q
- Quiet mode; suppress output, return status only
- -s
- Set (enable) the specified options
- -u
- Unset (disable) the specified options
- -o
- Restrict to options also settable with set -o
FAQ
What is the shopt command used for?
shopt is a Bash builtin that enables or disables shell options for the current session. These options modify shell behavior including globbing, history handling, directory navigation, and command completion. Without arguments, shopt lists all options and their current status. Use -s to enable and -u to disable specific options. The -q flag tests options silently, setting exit status 0 if enabled, 1 if disabled. Options set with shopt persist only for the current session. Add shopt commands to ~/.bashrc for permanent configuration.
How do I run a basic shopt example?
Run `shopt` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -p do in shopt?
Print shell options in a format reusable as input