I was looking for a way to check if a program is installed using Shell Script when I came across this answer which contained this code:
hash foo 2>&- || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
But that code isn’t very (human) readable, what is the alternative for that syntax?
Readability is very subjective. I particularly think the original is very readable, once you know that
||means a short-circuiting OR. So you read the original as “do this, OR this if that one fails”.The equivalent code without using
||is: