I'd like to have a command only execute if the preceding command's exit status was not 0.
i.e. Command 1 ^ Command 2 where Command 2 is only executed when Command 1 fails.
I'd like to have a command only execute if the preceding command's exit status was not 0.
i.e. Command 1 ^ Command 2 where Command 2 is only executed when Command 1 fails.
For this, use the double-pipe (||
) operator.
touch /asdf/fdasfds/fdasfdas || echo "Couldn't touch."
The second command is only executed when the first command returns non-zero, exactly as you specified.