In bash, is it possible to use these two operators to handle both of the exit statuses of the same command ? or if I want to handle both cases, I have to use an
if statement ?
Yes, It's possible
[[ "a" == "a" ]] && echo true || echo false
Try replacing "a" with "b", to see false:
[[ "b" == "a" ]] && echo true || echo false
This is the closest you can get:
your_main_command && run_on_success || run_on_failure
The caveat is that
run_on_failure will be run if any of the preceding commands i.e.