how to make switch execute 2 cases?
I tried with the following code, but it execute only the first case
#!/bin/sh
action="titi"
case "$action" in
toto|titi)
echo "1_$action"
;;
tata|titi)
echo "2_$action"
;;
esac
The case
statement in bash executes the commands in the COMMAND-LIST
for the first match only.
However, In bash version 4
or later introduced the ;&
terminator. The ;;&
operator is like ;;
, except the case statement doesn't terminate after executing the associated list - Bash just continues testing the next pattern as though the previous pattern didn't match. Using these terminators, a case statement can be configured to test against all patterns, or to share code between blocks, for example.
Reference: Excerpt taken from http://wiki.bash-hackers.org/syntax/ccmd/case
So if you have bash v 4 or later
this would give your desired result:
#!/bin/sh
action="titi"
case "$action" in
toto|titi)
echo "1_$action"
;;&
tata|titi)
echo "2_$action"
;;
esac
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With