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