Bash shell options bashopts | linux
BASHOPTS is new in bash 4.1. It is a list of the enabled shell options (shopts). It gives the same information as shopt | grep -w on , but in a more easily machine-parsable manner. This is a read-only variable; you can change what it reports with the shopt builtin (-s to set a flag, -u to unset it):
$ shopt mailwarn
mailwarn off
$ echo $BASHOPTS
checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:hostcomplete:interactive
_comments:progcomp:promptvars:sourcepath
$ shopt -s mailwarn
$ shopt mailwarn
mailwarn on
$ echo $BASHOPTS
checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:hostcomplete:interactive
_comments:mailwarn:progcomp:promptvars:sourcepath
$ shopt -u mailwarn
$ shopt mailwarn
mailwarn off
$ echo $BASHOPTS
checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:hostcomplete:interactive
_comments:progcomp:promptvars:sourcepath
$
There are 40 shell options in bash 4.1, all documented in the bash man page; some of the more useful and interesting options are:
➤➤ checkhash — This will check to see if a hashed PATH entry still exists before attempting to execute the file.
➤➤ checkwinsize — This updates the LINES and COLUMNS variables after every command (effectively, as part of PROMPT_COMMAND); this means that if you resize the window and run a command which uses these variables , the running shell will auto- matically pick up the new window size. Without this flag, the resize command must be run manually to pick up the new window size.
➤➤ cmdhist — This reduces multi-line commands, such as:
$ for i in `seq 10 -1 1`
> do
> echo -en “${i} …”
> done ; echo “boom”
10 …9 …8 …7 …6 …5 …4 …3 …2 …1 …boom
$
which will be collapsed into a single line in the shell history, like this:
for i in `seq 10 -1 1`; do echo -en “${i} …”; done; echo “boom”
➤➤ hostcomplete — This is a nifty trick of bash which extends command completion to host names. If I want to log in to host declan from atomic, I can type:
steve@atomic:~$
ssh steve@de <tab>
and bash will find declan in /etc/hosts, and expand the command to ssh steve@declan. This works with /etc/hosts, but not DNS; the lookup would not be possible in the same way.
➤➤ login_shell — This is set if the current shell is a login shell; it is read-only.
In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.