How can I reduce the following bash script?
grep -P "STATUS: (?!Perfect)" recess.txt && exit 1 exit 0
It seems like I should be able to do it with a single command, but I have a total of 3 here.
My program should:
The answer award goes to the tightest script. Thanks!
Program should have exit status 0 for this file:
FILE: styles.css STATUS: Perfect! FILE: contour-styles.css STATUS: Perfect!
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
Normally the exit status is 0 if a line is selected, 1 if no lines were selected, and 2 if an error occurred. However, if the -q or --quiet or --silent option is used and a line is selected, the exit status is 0 even if an error occurred. Other grep implementations may exit with status greater than 2 on error.
After a function returns, $? gives the exit status of the last command executed in the function. This is Bash's way of giving functions a "return value." [ 1] Following the execution of a pipe, a $? gives the exit status of the last command executed.
All of the Bash builtins return an exit status of zero if they succeed and a non-zero status on failure, so they may be used by the conditional and list constructs. All builtins return an exit status of 2 to indicate incorrect usage, generally invalid options or missing arguments.
Just negate the return value.
! grep -P "STATUS: (?!Perfect)" recess.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With