bash case statement fall through


bash case statement fall through

Short answer is that there isn't a fall through.  Here is an example from http://en.wikipedia.org/wiki/Switch_statement.

Most people just want a or functionality so here is how you achieve that.

case $n in
    0)      echo 'You typed 0.';;
    1|9)    echo "$n is a perfect square.";;
    3|5|7)  echo "$n is a prime number.";;
    4)    echo "$n is a perfect square.
$n is an even number";;
    2|6|8)    echo "$n is an even number.";;
    *)      echo 'Only single-digit numbers are allowed.';;
esac

Comments

Anthony said…
At least according to current (2011-08-04) Wikipedia, the "fallthrough" mechanism in Bash is to use ";&" as the terminating token at the end of the actions for a particular case, instead of ";;".

Popular posts from this blog

Vim vi how to reload a file your editing