我知道我能做到这一点的退出状态...打击“不”:反转命令
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