Bash:与grep命令处于相反状态的单线退出吗? [英] Bash: One-liner to exit with the opposite status of a grep command?
本文介绍了Bash:与grep命令处于相反状态的单线退出吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何减少以下bash脚本?
How can I reduce the following bash script?
grep -P "STATUS: (?!Perfect)" recess.txt && exit 1
exit 0
似乎我应该可以用一个命令来完成,但是这里总共有3个.
It seems like I should be able to do it with a single command, but I have a total of 3 here.
我的程序应该:
- 阅读cess.txt
- 退出1(或非零)(如果其中包含一行"STATUS:"为NOT完美"的行)
- 如果不存在这样的行,则退出0(即所有"STATUS:"行均为"Perfect")
答案是最严格的脚本.谢谢!
The answer award goes to the tightest script. Thanks!
该文件的程序应具有退出状态0 :
FILE: styles.css
STATUS: Perfect!
FILE: contour-styles.css
STATUS: Perfect!
此文件的程序应具有退出状态1 (或非零):
Program should have exit status 1 (or non-zero) for this file:
FILE: styles.css
STATUS: Perfect!
FILE: contour-styles.css
STATUS: Busted
FAILURES: 1 failure
Id's should not be styled
1. #asdf
推荐答案
只需否定返回值.
! grep -P "STATUS: (?!Perfect)" recess.txt
这篇关于Bash:与grep命令处于相反状态的单线退出吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文