我知道我能做到這一點的退出狀態...打擊「不」:反轉命令
if diff -q $f1 $f2
then
echo "they're the same"
else
echo "they're different"
fi
但是,如果我想否定我正在檢查的條件是什麼?即是這樣的(這顯然是行不通的)
if not diff -q $f1 $f2
then
echo "they're different"
else
echo "they're the same"
fi
我可以做這樣的事情......
diff -q $f1 $f2
if [[ $? > 0 ]]
then
echo "they're different"
else
echo "they're the same"
fi
當我檢查前一個命令的退出狀態是否大於0但這感覺有點尷尬。有沒有更習慣的方式來做到這一點?
哇, 謝謝。我想這很容易。我發誓我花了15分鐘閱讀bash文檔之前發佈此沒有發現任何東西... – Coquelicot 2013-02-25 17:49:00