gpt4 book ai didi

狂欢 "not": inverting the exit status of a command

转载 作者:行者123 更新时间:2023-11-29 08:59:33 24 4
gpt4 key购买 nike

我知道我能做到...

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 ...

关于狂欢 "not": inverting the exit status of a command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15073048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com