set -o posix will set the POSIX attribute of the bash shell.

How can we check if an attribute has been set up or not?

  • 2
    @JeffSchaller extglob belongs to the shopt list of options, but the set list of options is not explained in that answer. (shopt posix will fail).
    – user79743
    Mar 14, 2016 at 23:21

2 Answers 2


There are two lists of options in bash. One for shopt and one for set.

Check one option.

To print an specific option (without changing it) for shopt, use shopt -p name:

$ shopt -p xpg_echo
shopt -u xpg_echo

And for set, use: shopt -po name (yes, you may use shopt -op for set list).

$  shopt -po xtrace
set +o xtrace

List options.

To list all options from shopt, use shopt (or reusable shopt -p).
Also shopt -s or shopt -u could be used.

The way to list all options to set is with set -o (related: set +o).
Or: shopt -o is equivalent to set -o and shopt -op is to set +o.


From LESS=+/'^ *shopt \[' man bash:

With no options, or with the -p option, a list of all settable options is displayed, If either -s or -u is used with no optname arguments, the display is limited to those options which are set or unset, respectively.

From LESS=+/'^ *set \[' man bash:

If -o is supplied with no option-name, the values of the current options are printed. If +o is supplied with no option-name, a series of set commands to recreate the current option settings is displayed on the standard output.


$ 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


$  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

It is worth mentioning about shopt -op which actually lists set options:

$ 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
  • Thanks. What do the env var LESSant its value +/'^ *set \[' in LESS=+/'^ *set \[' man bash mean?
    – Tim
    Mar 15, 2016 at 0:31
  • @Tim Just copy the whole line to your shell and execute it.
    – user79743
    Mar 15, 2016 at 1:05

Use something like

if shopt -qo posix ; then

To unset the option, use

set +o posix

See man bash, help set, and help shopt for more details.

  • Thanks. How can I unset it? Is it correct that the command unset is to unset a variable or function, not a shell attribute?
    – Tim
    Mar 14, 2016 at 22:05
  • @Tim: updated, simplified.
    – choroba
    Mar 14, 2016 at 22:08
  • Thanks. help set says set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]. Does it mean that the option -o must be followed by an option argument option-name?
    – Tim
    Mar 14, 2016 at 22:12
  • Thanks. Sorry I missed the + part. But still doesn't help set implies -o must be followed by an option argument option-name?
    – Tim
    Mar 14, 2016 at 22:14
  • @Tim: My version says much more.
    – choroba
    Mar 14, 2016 at 22:14

Not the answer you're looking for? Browse other questions tagged .