I am in the process of reading this bash guide from the Linux Documentation Project. On page 81 and 82 there's a short example script for testing whether an option is set:
if [ -o noclobber ]
then
echo "Your files are protected against accidental overwriting using redirection."
fi
I have run into some weird behavior when trying to negate the test. I am getting a return value of 0 for all options that are turned on for [ -o OPTION ]
and [ ! -o OPTION ]
. Here's an example:
$ set -o | grep errex
errexit off
$ [ -o errexit ]; echo $?
1
$ [ ! -o errexit ]; echo $?
0
$ set -o | grep history
history on
$ [ -o history ]; echo $?
0
$ [ ! -o history ]; echo $?
0