時出現奇怪行爲我正在閱讀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