加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 01:34:14 所属栏目:安全 来源:网络整理
导读:我知道我能做到这一点…… if diff -q $f1 $f2then echo "they're the same"else echo "they're different"fi 但是,如果我想否定我正在检查的条件呢?即这样的事情(显然不起作用) if not diff -q $f1 $f2then echo "they're different"else echo "they're th
我知道我能做到这一点……
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 ...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读