]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/case.tests
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / case.tests
CommitLineData
8868edaf
CR
1# This program is free software: you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation, either version 3 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program. If not, see <http://www.gnu.org/licenses/>.
13#
3185942a
JA
14case foo in
15bar) echo skip ;;
16foo) echo fallthrough ;&
17bax) echo to here ;&
18qux) echo and here;;
19fop) echo but not here;;
20esac
21
22case foobar in
23bar) echo skip ;;
24foo*) echo retest ;;&
25*bar) echo and match ;;&
26qux) echo but not this ;;
27esac
0001803f
CR
28
29case a in
30a) echo no more clauses;&
31esac
ac50fbac
CR
32
33x=0 y=1
34case 1 in
35 $((y=0)) ) ;;
36 $((x=1)) ) ;&
37 $((x=2)) ) echo $x.$y ;;
38esac
39
40unset x
41readonly xx=1
42case 1 in $((xx++)) ) echo hi1 ;; *) echo hi2; esac
43echo ${xx}.$?
44
a0c0a00f
CR
45unset var empty
46
47var=
48case ']' in
49[$var]*[$var]) echo matches 1;;
50*) echo no match 1 ;;
51esac
52
53case abc in ( [] ) echo yes ;; ( * ) echo no ;; esac
54empty=''
55case abc in ( ["$empty"] ) echo yes ;; ( * ) echo no ;; esac
56
57case abc in ( [] | [!a-z]* ) echo yes ;; ( * ) echo no ;; esac
58empty=''
59case abc in ( ["$empty"] | [!a-z]* ) echo yes ;; ( * ) echo no ;; esac
60
61case abc in (["$empty"]|[!a-z]*) echo yes ;; (*) echo no ;; esac
62
63case " " in ( [" "] ) echo ok;; ( * ) echo no;; esac
64
ac50fbac
CR
65# tests of quote removal and pattern matching
66${THIS_SH} ./case1.sub
d233b485
CR
67${THIS_SH} ./case2.sub
68${THIS_SH} ./case3.sub
69${THIS_SH} ./case4.sub