How to test if the exit code of a command equals a given value in line? I’m looking for an equivalent to the following without the need to run the command first and retrieve $?
:
diff a.txt b.txt
if [ $? = 2 ]; then
echo diff failed
exit 2
fi
This is different from the following questions because this question asks about checking exit code equal to a specific value rather than being zero or not:
- Bash check return code of a command inline
- Bash conditional based on exit code of command