时出现奇怪行为我正在阅读Linux文档项目中的this bash指南。 第81页和82有一个用于测试的短示例脚本选项是否设置:检查shell选项是否设置为[-o OPTION],当OPTION为
if [ -o noclobber ]
then
echo "Your files are protected against accidental overwriting using redirection."
fi
试图否定测试时,我遇到了一些奇怪的行为。对于打开为[ -o OPTION ]
和[ ! -o OPTION ]
的所有选项,我得到的返回值为0。以下是一个示例:
$ 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
我没有看到那个-o做你期望的'man test | grep -A1“\ -o”'。 – 2014-10-04 21:52:26