1 #!/bin/bash
2 #
3 # Test the case statement
4
5 ### Case statement
6 case a in
7 a) echo A ;;
8 *) echo star ;;
9 esac
10 # stdout: A
11
12 ### Case statement with ;;&
13 # ;;& keeps testing conditions
14 # NOTE: ;& and ;;& are bash 4 only, no on Mac
15 case a in
16 a) echo A ;;&
17 *) echo star ;;&
18 *) echo star2 ;;
19 esac
20 # stdout-json: "A\nstar\nstar2\n"
21 # N-I dash stdout-json: ""
22
23 ### Case statement with ;&
24 # ;& ignores the next condition. Why would that be useful?
25 case a in
26 a) echo A ;&
27 XX) echo two ;&
28 YY) echo three ;;
29 esac
30 # stdout-json: "A\ntwo\nthree\n"
31 # N-I dash stdout-json: ""
32
33 ### Case with empty condition
34 case $empty in
35 ''|foo) echo match ;;
36 *) echo no ;;
37 esac
38 # stdout: match