【发布时间】:2013-02-10 22:55:53
【问题描述】:
我知道我能做到……
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。不过这样感觉有点别扭。有没有更惯用的方法来做到这一点?
【问题讨论】:
标签: bash conditional