Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

set and shopt are both shell builtins that control various options. I often forget which options are set by which command, and occasionally which option sets/unsets (set +o/-o, shopt -s/-u). Why are there two different commands that seemingly do the same thing (and have different arguments to do so)? Is there any easy way/mnemonic to remember which options go with which command?

share|improve this question
Try looking at the second line of help set and help shopt to verify that even their authors think they do the same thing. – l0b0 Feb 22 '12 at 16:28
"Change the value of shell attributes" vs "Change the setting of each shell option". – Kevin Feb 22 '12 at 16:30
In Bash 4.1.5(1)-release it says "Set or unset values of shell options and positional parameters." and "Set and unset shell options.", respectively. – l0b0 Feb 22 '12 at 16:33
up vote 15 down vote accepted

As far as I know, the set -o options are the ones that are inherited from other Bourne-style shells (mostly ksh), and the shopt options are the ones that are specific to bash. There's no logic that I know of.

share|improve this answer
Any documentation which shows shopt is inherited ? – Felipe Alvarez Jul 3 '15 at 1:13

It looks like "set" options are inherited by subshells and shopts are not.

share|improve this answer
Nice catch. I wonder whether this is an intentional choice or a side-effect. – Kevin Jan 5 '13 at 19:09
@user29778 At least under bash 4.1.5(1) the options set with set are not inherited by subshells.Both set and shopt options are not inherited by subshells. – Martin May 7 '13 at 22:13
Can you point to the documentation that describes the inheritance characteristics of both set and shopt ? – Felipe Alvarez Jul 3 '15 at 1:12

The difference is in the changed enviroment variable used by the bash. Setting with the set command results in $SHELLOPTS. Setting with the shopt command results in $BASHOPTS.

share|improve this answer
Ugh! That is even more confusing. My brain wants to associate shopt with $ SHELLOPTS rather than $ BASHOPTS. – Bruno Bronosky Mar 22 at 16:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.