1 #### Lower Case with , and ,,
2 x='ABC DEF'
3 echo ${x,}
4 echo ${x,,}
5 echo empty=${empty,}
6 echo empty=${empty,,}
7 ## STDOUT:
8 aBC DEF
9 abc def
10 empty=
11 empty=
12 ## END
13
14 #### Upper Case with ^ and ^^
15 x='abc def'
16 echo ${x^}
17 echo ${x^^}
18 echo empty=${empty^}
19 echo empty=${empty^^}
20 ## STDOUT:
21 Abc def
22 ABC DEF
23 empty=
24 empty=
25 ## END
26
27 #### Lower Case with constant string (VERY WEIRD)
28 x='AAA ABC DEF'
29 echo ${x,A}
30 echo ${x,,A} # replaces every A only?
31 ## STDOUT:
32 aAA ABC DEF
33 aaa aBC DEF
34 ## END
35
36 #### Lower Case glob
37
38 # Hm with C.UTF-8, this does no case folding?
39 export LC_ALL=en_US.UTF-8
40
41 x='ABC DEF'
42 echo ${x,[d-f]}
43 echo ${x,,[d-f]} # This seems buggy, it doesn't include F?
44 ## STDOUT:
45 ABC DEF
46 ABC deF
47 ## END
48
49 #### ${x@Q}
50 x="FOO'BAR spam\"eggs"
51 eval "new=${x@Q}"
52 test "$x" = "$new" && echo OK
53 ## STDOUT:
54 OK
55 ## END
56
57 #### ${array@Q} and ${array[@]@Q}
58 array=(x 'y\nz')
59 echo ${array[@]@Q}
60 shopt -s compat_array
61 echo ${array@Q}
62 shopt -u compat_array
63 echo ${array@Q}
64 ## STDOUT:
65 'x' 'y\nz'
66 'x'
67 'x'
68 ## END
69 ## OK osh status: 1
70 ## OK osh STDOUT:
71 x $'y\\nz'
72 x
73 ## END
74
75 #### ${!prefix@} ${!prefix*} yields sorted array of var names
76 ZOO=zoo
77 ZIP=zip
78 ZOOM='one two'
79 Z='three four'
80
81 z=lower
82
83 argv.py ${!Z*}
84 argv.py ${!Z@}
85 argv.py "${!Z*}"
86 argv.py "${!Z@}"
87 for i in 1 2; do argv.py ${!Z*} ; done
88 for i in 1 2; do argv.py ${!Z@} ; done
89 for i in 1 2; do argv.py "${!Z*}"; done
90 for i in 1 2; do argv.py "${!Z@}"; done
91 ## STDOUT:
92 ['Z', 'ZIP', 'ZOO', 'ZOOM']
93 ['Z', 'ZIP', 'ZOO', 'ZOOM']
94 ['Z ZIP ZOO ZOOM']
95 ['Z', 'ZIP', 'ZOO', 'ZOOM']
96 ['Z', 'ZIP', 'ZOO', 'ZOOM']
97 ['Z', 'ZIP', 'ZOO', 'ZOOM']
98 ['Z', 'ZIP', 'ZOO', 'ZOOM']
99 ['Z', 'ZIP', 'ZOO', 'ZOOM']
100 ['Z ZIP ZOO ZOOM']
101 ['Z ZIP ZOO ZOOM']
102 ['Z', 'ZIP', 'ZOO', 'ZOOM']
103 ['Z', 'ZIP', 'ZOO', 'ZOOM']
104 ## END
105
106 #### ${!prefix@} matches var name (regression)
107 hello1=1 hello2=2 hello3=3
108 echo ${!hello@}
109 hello=()
110 echo ${!hello@}
111 ## STDOUT:
112 hello1 hello2 hello3
113 hello hello1 hello2 hello3
114 ## END
115
116 #### ${var@a} for attributes
117 array=(one two)
118 echo ${array@a}
119 declare -r array=(one two)
120 echo ${array@a}
121 declare -rx PYTHONPATH=hi
122 echo ${PYTHONPATH@a}
123
124 # bash and osh differ here
125 #declare -rxn x=z
126 #echo ${x@a}
127 ## STDOUT:
128 a
129 ar
130 rx
131 ## END
132
133 #### ${var@a} error conditions
134 echo [${?@a}]
135 ## STDOUT:
136 []
137 ## END
138
139 #### undef and @P @Q @a
140 $SH -c 'echo ${undef@P}'
141 echo status=$?
142 $SH -c 'echo ${undef@Q}'
143 echo status=$?
144 $SH -c 'echo ${undef@a}'
145 echo status=$?
146 ## STDOUT:
147
148 status=0
149
150 status=0
151
152 status=0
153 ## END
154 ## OK osh STDOUT:
155
156 status=0
157 ''
158 status=0
159
160 status=0
161 ## END
162
163
164 #### argv array and @P @Q @a
165 $SH -c 'echo ${@@P}' dummy a b c
166 echo status=$?
167 $SH -c 'echo ${@@Q}' dummy a 'b\nc'
168 echo status=$?
169 $SH -c 'echo ${@@a}' dummy a b c
170 echo status=$?
171 ## STDOUT:
172 a b c
173 status=0
174 'a' 'b\nc'
175 status=0
176
177 status=0
178 ## END
179 ## OK osh STDOUT:
180 status=1
181 a $'b\\nc'
182 status=0
183 a
184 status=0
185 ## END
186
187 #### assoc array and @P @Q @a
188
189 # note: "y z" causes a bug!
190 $SH -c 'declare -A A=(["x"]="y"); echo ${A@P} - ${A[@]@P}'
191 echo status=$?
192
193 # note: "y z" causes a bug!
194 $SH -c 'declare -A A=(["x"]="y"); echo ${A@Q} - ${A[@]@Q}'
195 echo status=$?
196
197 $SH -c 'declare -A A=(["x"]=y); echo ${A@a} - ${A[@]@a}'
198 echo status=$?
199 ## STDOUT:
200 - y
201 status=0
202 - 'y'
203 status=0
204 A - A
205 status=0
206 ## END
207 ## OK osh STDOUT:
208 status=1
209 status=1
210 A - A
211 status=0
212 ## END
213
214 #### ${!var[@]@X}
215 # note: "y z" causes a bug!
216 $SH -c 'declare -A A=(["x"]="y"); echo ${!A[@]@P}'
217 if test $? -ne 0; then echo fail; fi
218
219 # note: "y z" causes a bug!
220 $SH -c 'declare -A A=(["x y"]="y"); echo ${!A[@]@Q}'
221 if test $? -ne 0; then echo fail; fi
222
223 $SH -c 'declare -A A=(["x"]=y); echo ${!A[@]@a}'
224 if test $? -ne 0; then echo fail; fi
225 # STDOUT:
226
227
228
229 # END
230 ## OK osh STDOUT:
231 fail
232 'x y'
233 a
234 ## END
235
236 #### ${#var@X} is a parse error
237 # note: "y z" causes a bug!
238 $SH -c 'declare -A A=(["x"]="y"); echo ${#A[@]@P}'
239 if test $? -ne 0; then echo fail; fi
240
241 # note: "y z" causes a bug!
242 $SH -c 'declare -A A=(["x"]="y"); echo ${#A[@]@Q}'
243 if test $? -ne 0; then echo fail; fi
244
245 $SH -c 'declare -A A=(["x"]=y); echo ${#A[@]@a}'
246 if test $? -ne 0; then echo fail; fi
247 ## STDOUT:
248 fail
249 fail
250 fail
251 ## END
252
253 #### ${!A@a} and ${!A[@]@a}
254 declare -A A=(["x"]=y)
255 echo x=${!A[@]@a}
256 echo x=${!A@a}
257
258 # OSH prints 'a' for indexed array because the AssocArray with ! turns into
259 # it. Disallowing it would be the other reasonable behavior.
260
261 ## STDOUT:
262 x=
263 x=
264 ## END