Bash“not”:反转命令的退出状态

前端之家收集整理的这篇文章主要介绍了Bash“not”:反转命令的退出状态前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我知道我能做到这一点……
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.但这感​​觉有点尴尬.有没有比较惯用的方法呢?

if ! diff -q $f1 $f2; then ...
原文链接:https://www.f2er.com/bash/383364.html

猜你在找的Bash相关文章