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($c) {
case 1:
do_this();
break;
case 2:
case 3:
do_what_you_are_supposed_to_do();
break;
default:
do_nothing();
}
I want the same in Bash:
case "$C" in
"1")
do_this()
;;
"2")
"3")
do_what_you_are_supposed_to_do()
;;
*)
do_nothing();
;;
esac
This somehow doesn't work: function do_what_you_are_supposed_to_do()
should be fired when $C is 2 OR 3.
function fname { echo "Inside fname"; return 0; }
orfname() { echo "inside fname"; return 0; }
placing parens on a function call can look like it's a function defintion. Functions should be called like any other command line program such asmv
,cp
,rsync
,ls
,cd
, etc... In this case we call fname like so:fname $ARGS
.do_nothing()
shall be a SKIP statement? Use:
.