in Bash, CODING, Tips & Tricks

Succinct version of `if..elif`

Instead of writing out a large block for an if / elif such as…

if [[ $foo == $bar ]]; then
    echo "yes"
else
    echo "no
fi

a much shorter version can be used instead:

[[ $foo == $bar ]] && echo "yes" || echo "no"

A simple [[ condition ]] && positive result || negative result