Possible to match multiple conditions in one case statement?
You can use the ;;&
conjunction. From man bash
:
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.
Ex. given
$ cat myscript
#!/bin/bash
NOW=$(date -d "$1" +"%a")
case $NOW in
Mon)
echo "Mon";;
Tue|Wed|Thu|Fri)
echo "Tue|Wed|Thu|Fri";;&
Fri|Sat|Sun)
echo "Fri|Sat|Sun";;
*) ;;
esac
then
$ ./myscript thursday
Tue|Wed|Thu|Fri
$ ./myscript friday
Tue|Wed|Thu|Fri
Fri|Sat|Sun
$ ./myscript saturday
Fri|Sat|Sun
For more information (including equivalents in other shells) see
- Can bash case statements cascade?