I am looking for the correct syntax of the switch statement with fallthrough cases in Bash (ideally case-insensitive). In PHP I would program it like:
switch
() behind function names in bash unless you like to define them.[23] in case to match 2 or 3'' instead of ""If enclosed in "", the interpreter (needlessly) tries to expand possible variables in the value before matching.
case "$C" in
'1')
do_this
;;
[23])
do_what_you_are_supposed_to_do
;;
*)
do_nothing
;;
esac
For case insensitive matching, you can use character classes (like [23]):
case "$C" in
# will match C='Abra' and C='abra'
[Aa]'bra')
do_mysterious_things
;;
# will match all letter cases at any char like `abra`, `ABRA` or `AbRa`
[Aa][Bb][Rr][Aa])
do_wild_mysterious_things
;;
esac
But abra didn't hit anytime because it will be matched by the first case.
If needed, you can omit ;; in the first case to continue testing for matches in following cases too. (;; jumps to esac)