作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道我能做到...
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/
我是一名优秀的程序员,十分优秀!