In the case below, the report
command must always be executed but I need to get an exit status 1 if the test
command fails:
test;report
echo $?
0
How can I do it in a single bash line without creating a shell script?
bashexit-status
In the case below, the report
command must always be executed but I need to get an exit status 1 if the test
command fails:
test;report
echo $?
0
How can I do it in a single bash line without creating a shell script?
Best Answer
Save and reuse
$?
.If you have multiple test commands and you want to run them all, but keep track of whether one has failed, you can use bash's ERR trap.