Ubuntu – In bash, is there a way I can make shorter (if or) statements

bash

if [ foo = bar -o foo = car -o foo = jar -o foo = foo ]
  then
    echo yes
fi

To keep things more organized, I would like to try to match it to a list, such as

if [ foo = {bar,car,jar,foo} ] ; then

Obviously the curly brace expansion method didn't work or else I wouldn't be here!
But I would like to know if something like this is possible at all.

Best Answer

I suggest using case structure. Something like:

case $foo in
    foo|car|bar|jar) echo yes ;;
    *) ;;
esac

If you like, you can add a command between *) and ;; to be executed when $foo doesn't match foo, car, bar, or jar. For example, you could print a message with echo 'wrong input' or something like that.