What does ||: mean in the shell?
I am looking at shell script code and I don't know what is the purpose of the double pipe (||) followed by a colon (:), can someone explain? eg.
$ <some_command> >/dev/null 2>&1 || :
||
is boolean or.
:
is a no-op command that does nothing and exits with a truthful status.
So, anything || :
unconditionally returns true.
So some_command_that_may_fail ||:
it will always be successful.
This is important if there is an set -e
ERR or trap in use but you don't want your script to exit or throw an error if the command fails.
: colon is noop, double is OR operation, so ...
execute some_command OR (if some_command fails) execute: (this is operation no)
|| means the second is executed only if the first command of the command fails. In this case, the second command means "do nothing"