Report issue Add example

shopt

Display and set shell execution options.

Description

The shopt command is used to display and set behavioral options in the shell to enhance shell usability. If the shopt command is used without any options, it displays all settable shell execution options.

Syntax

shopt [option] [parameter]

Options

-s: Enable (set) the specified shell behavior options;
-u: Disable (unset) the specified shell behavior options.

Parameters

shell options: Specify the shell options to operate on.

Examples

Use the shopt command to display all current settable shell execution options:

shopt           # Output all settable shell execution options
autocd         	off
cdable_vars    	off
cdspell        	off
checkhash      	off
checkjobs      	off
checkwinsize   	on
cmdhist        	on
compat31       	off
compat32       	off
compat40       	off
compat41       	off
compat42       	off
compat43       	off
complete_fullquote	on
direxpand      	off
dirspell       	off
dotglob        	off
execfail       	off
expand_aliases 	on
extdebug       	off
extglob        	off
extquote       	on
failglob       	off
force_fignore  	on
globasciiranges	off
globstar       	off
gnu_errfmt     	off
histappend     	on
histreedit     	off
histverify     	off
hostcomplete   	on
huponexit      	off
inherit_errexit	off
interactive_comments	on
lastpipe       	off
lithist        	off
login_shell    	on
mailwarn       	off
no_empty_cmd_completion	off
nocaseglob     	off
nocasematch    	off
nullglob       	off
progcomp       	on
promptvars     	on
restricted_shell	off
shift_verbose  	off
sourcepath     	on
syslog_history 	off
xpg_echo       	off

As shown above, the status of the "cdspell" option is "off", meaning the cd spelling check option is disabled. Now, you can use the shopt command to enable it:

shopt -s cdspell          # Enable cd spelling check

After executing the command, the status of this option will change to "on". You can display the shell execution options again to verify:

cdspell on                # cdspell option is enabled

Users can verify if the option has been successfully enabled by executing the cd command.