1 | ## compare_shells: dash bash mksh
|
2 |
|
3 | # Cases from
|
4 | # http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
|
5 |
|
6 | # My tests
|
7 |
|
8 | #### Empty for loop is allowed
|
9 | set -- a b
|
10 | for x in; do
|
11 | echo hi
|
12 | echo $x
|
13 | done
|
14 | ## stdout-json: ""
|
15 |
|
16 | #### Empty for loop without in. Do can be on the same line I guess.
|
17 | set -- a b
|
18 | for x do
|
19 | echo hi
|
20 | echo $x
|
21 | done
|
22 | ## STDOUT:
|
23 | hi
|
24 | a
|
25 | hi
|
26 | b
|
27 | ## END
|
28 |
|
29 | #### Empty case statement
|
30 | case foo in
|
31 | esac
|
32 | ## stdout-json: ""
|
33 |
|
34 | #### Last case without ;;
|
35 | foo=a
|
36 | case $foo in
|
37 | a) echo A ;;
|
38 | b) echo B
|
39 | esac
|
40 | ## stdout: A
|
41 |
|
42 | #### Only case without ;;
|
43 | foo=a
|
44 | case $foo in
|
45 | a) echo A
|
46 | esac
|
47 | ## stdout: A
|
48 |
|
49 | #### Case with optional (
|
50 | foo=a
|
51 | case $foo in
|
52 | (a) echo A ;;
|
53 | (b) echo B
|
54 | esac
|
55 | ## stdout: A
|
56 |
|
57 | #### Empty action for case is syntax error
|
58 | # POSIX grammar seems to allow this, but bash and dash don't. Need ;;
|
59 | foo=a
|
60 | case $foo in
|
61 | a)
|
62 | b)
|
63 | echo A ;;
|
64 | d)
|
65 | esac
|
66 | ## status: 2
|
67 | ## OK mksh status: 1
|
68 |
|
69 | #### Empty action is allowed for last case
|
70 | foo=b
|
71 | case $foo in
|
72 | a) echo A ;;
|
73 | b)
|
74 | esac
|
75 | ## stdout-json: ""
|
76 |
|
77 | #### Case with | pattern
|
78 | foo=a
|
79 | case $foo in
|
80 | a|b) echo A ;;
|
81 | c)
|
82 | esac
|
83 | ## stdout: A
|
84 |
|
85 |
|
86 | #### Bare semi-colon not allowed
|
87 | # This is disallowed by the grammar; bash and dash don't accept it.
|
88 | ;
|
89 | ## status: 2
|
90 | ## OK mksh status: 1
|
91 |
|
92 |
|
93 |
|
94 | #
|
95 | # Explicit tests
|
96 | #
|
97 |
|
98 |
|
99 |
|
100 | #### Command substitution in default
|
101 | echo ${x:-$(ls -d /bin)}
|
102 | ## stdout: /bin
|
103 |
|
104 |
|
105 | #### Arithmetic expansion
|
106 | x=3
|
107 | while [ $x -gt 0 ]
|
108 | do
|
109 | echo $x
|
110 | x=$(($x-1))
|
111 | done
|
112 | ## STDOUT:
|
113 | 3
|
114 | 2
|
115 | 1
|
116 | ## END
|
117 |
|
118 | #### Newlines in compound lists
|
119 | x=3
|
120 | while
|
121 | # a couple of <newline>s
|
122 |
|
123 | # a list
|
124 | date && ls -d /bin || echo failed; cat tests/hello.txt
|
125 | # a couple of <newline>s
|
126 |
|
127 | # another list
|
128 | wc tests/hello.txt > _tmp/posix-compound.txt & true
|
129 |
|
130 | do
|
131 | # 2 lists
|
132 | ls -d /bin
|
133 | cat tests/hello.txt
|
134 | x=$(($x-1))
|
135 | [ $x -eq 0 ] && break
|
136 | done
|
137 | # Not testing anything but the status since output is complicated
|
138 | ## status: 0
|
139 |
|
140 | #### Multiple here docs on one line
|
141 | cat <<EOF1; cat <<EOF2
|
142 | one
|
143 | EOF1
|
144 | two
|
145 | EOF2
|
146 | ## STDOUT:
|
147 | one
|
148 | two
|
149 | ## END
|
150 |
|
151 | #### cat here doc; echo; cat here doc
|
152 | cat <<EOF1; echo two; cat <<EOF2
|
153 | one
|
154 | EOF1
|
155 | three
|
156 | EOF2
|
157 | ## STDOUT:
|
158 | one
|
159 | two
|
160 | three
|
161 | ## END
|