bash: switch case flow control

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

case $var in
    pattern1 )
        statements ;;
    pattern2 )
        statements ;;
    *)
        statemest ;;
esac

Note the two consecutive semi-column ";;" which are a necessary part of the syntax!
The *) case is the default choice if none other apply.

#!/bin/bash
format() {
        case "$1" in
        'banana' | 'apple' )
                echo 'It is a fruit.';;
        'cat' )
                echo 'It is an animal.';;
        esac
}

print_category "banana"
print_category "cat"
print_category "apple"