So I have a script like this:
somecommad | grep --invert-match something
I'd like to be able to conditionally run a different command if somecommand
fails. Here's what I tried:
somecommand | grep --invert-match something || {
echo 'Oops'
}
But that didn't work (the grep
wasn't executed). What is the proper way to do this?
PIPESTATUS
array: see for example Get exit status of process that's piped to anothergrep
starts before you can necessarily know ifsomecommand
has failed or not. Do you want to the other command's output to go togrep
as well?{ somecommand || { echo Oops; }; } | grep ...
.