New ;& and ;;& operators were introduced in Bash
4.0
and although they both might be useful in similar situations I think
they are of no use in your case. This is what man bash says about
these operators:
If the ;; operator is used, no subsequent matches are attempted after
the first pattern match. Using ;& in place of ;; causes execution to
continue with the list associated with the next set of patterns. Using
;;& in place of ;; causes the shell to test the next pattern list in
the statement, if any, and execute any associated list on a successful
match.
In other words, ;& is a fall through and as we know it from C and
;;& makes bash check remaining cases instead of returning from
case block entirely. You can find a nice example of ;;& in action
here: https://stackoverflow.com/a/24544780/3691891.
That being said, neither ;& nor ;;& could be used in your script
because both of them would go to *) that would be always run.
The following script works and does what you want without re-arranging
the logic but consider it only as an example and never rely on it, it's too fragile.
I've taken the idea from
here:
#!/usr/bin/env bash
function jumpto
{
label=$1
cmd=$(sed -n "/$label:/{:a;n;p;ba};" "$0" | grep -v ':$')
cmd=$(echo "$cmd" | sed 's,;;,,')
cmd=$(echo "$cmd" | sed 's,esac,,')
eval "$cmd"
}
input="foo"
VAR="1"
case $input in
foo)
if [ $VAR = "1" ]; then
printf "perform fallthrough\n"
jumpto ft
else
printf "do not perform fallthrough\n"
fi
;;
*)
ft:
echo "fallthrough worked!"
;;
esac