Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
3  
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
1  
"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
add comment

3 Answers

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
1  
@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
add comment

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
add comment

Your Answer

 
discard

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.