1 # must do this because posix mode causes process substitution to be disabled
2 # and flagged as a syntax error, which causes the shell to exit
10 HOME=/usr/homes/chet # to make the check against new-exp.right work
12 recho "${undef-"foo bar"}" # should be foo bar
14 recho "${und="foo"}" # should be foo
23 expect $0: 'HOME: }: syntax error: operand expected (error token is "}")'
24 recho "${HOME:`echo }`}" # should be a math error -- bad substring substitution
28 x=${_ENV[(_$-=0)+(_=1)-_${-%%*i*}]}
34 recho ${HOME:-`echo }`}
36 recho ${HOME:-`echo "}"`}
38 recho "${HOME:-`echo "}"`}"
40 recho "$(echo "${HOME}")"
42 recho "$(echo "$(echo ${HOME})")"
44 recho "$(echo "$(echo "${HOME}")")"
52 recho "${P#\*}" # should be @*
55 recho "$(echo ")")" # should be )
57 recho "$(echo "\")\"")" # should be ")"
61 recho -${foo}- # should be -abcd -
63 recho -${foo% *}- # should be -abcd -
65 recho -${foo%% *}- # should be -abcd-
69 echo -n $foo' ' ; echo foo
72 echo -n $foo" " ; echo foo
75 echo -n "$foo " ; echo foo
78 echo -e "$foo\c " ; echo foo
81 echo -e $foo"\c " ; echo foo
83 # make sure backslashes are preserved in front of characters that are not
84 # valid backslash escapes
94 recho ${z:4:3} ${z:${#z}-3:3}
97 recho ${z:4:3} ${z: -3:3}
102 expect '<abcdefghijklmnop>'
105 expect '<abcdefghijklmnop>'
108 set 'ab cd' 'ef' 'gh ij' 'kl mn' 'op'
109 expect '<ab cd> <ef>'
112 expect '<gh ij> <kl mn>'
115 expect '<gh ij> <kl mn> <op>'
118 expect '<ab cd> <ef> <gh ij> <kl mn> <op>'
121 # indirect variable references
122 expect '<abcdefghijklmnop>'
134 expect '<abcdefghijklmnop>'
136 expect '<abcdefghijklmnop>'
145 expect $0: ABX: unbound variable
149 expect $0: '$6: cannot assign in this way'
154 # sed-like variable substitution
172 av=(abcd efgh ijkl mnop qrst uvwx)
181 recho ${av[1]/%ab/xx}
187 recho ${av[1]//??/za}
189 recho ${av[1]//#??/za}
191 recho ${av[1]//%??/za}
193 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
195 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
196 recho ${av[@]/#*/yyy}
197 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
198 recho ${av[@]/%*/yyy}
199 expect '<yyy> <efgh> <ijkl> <mnop> <qrst> <uvwx>'
200 recho ${av[@]/a*/yyy}
201 expect '<abxx> <efxx> <ijxx> <mnxx> <qrxx> <uvxx>'
202 recho ${av[@]/%??/xx}
204 set abcd efgh ijkl mnop qrst uvwx
208 expect '<xxcd> <xxgh> <xxkl> <xxop> <xxst> <xxwx>'
210 expect '<xxcd> <xxgh> <xxkl> <xxop> <xxst> <xxwx>'
216 expect '<zaza> <zaza> <zaza> <zaza> <zaza> <zaza>'
218 expect '<zacd> <zagh> <zakl> <zaop> <zast> <zawx>'
220 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
222 expect '<yyy> <efgh> <ijkl> <mnop> <qrst> <uvwx>'
224 expect '<abcd> <efgh> <ijkl> <mnop> <qrst> <uvwyyy>'
230 # run process substitution tests in a subshell so that syntax errors
231 # caused by a shell not implementing process substitution (e.g., one
232 # built on a NeXT) will not cause the whole test to exit prematurely
233 ${THIS_SH} ./new-exp1.sub
235 # run the tests of $(<filename) in a subshell to avoid cluttering up
237 ${THIS_SH} ./new-exp2.sub
241 expect $0: '${#:}: bad substitution'
265 recho ${foo:-"$zbcd"}
287 # this disagrees with sh and ksh, but I think it is right according
290 recho "${foo:-"$z1"}"
293 expect '<ab> <cd> <ef> <gh>'
295 expect '<ab> <cd> <ef> <gh>'
297 expect '<ab> <cd> <ef> <gh>'
304 recho ${foo:-$xxx"$@"}
306 recho "${foo:-$xxx$@}"
308 recho "${foo:-$xxx"$@"}"
326 AB='abcdefghijklmnopqrstuvwxyz'
355 set $'\1' $'\2' $'\177'
377 # out-of-range substrings
385 expect '<./new-exp.tests: -2: substring expression < 0>'
394 # make sure null patterns work
405 # another case that caused a core dump in bash-2.0
406 XPATH=/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin::/usr/bin/X11:/sbin:/usr/sbin
410 xx=(ar as at au av aw ax ay az)
424 set -- ar as at au av aw ax ay az
440 ( recho $9 ; echo after 1)
441 ( recho ${9} ; echo after 2)
442 ( recho $UNSET ; echo after 3)
443 ( recho ${UNSET} ; echo after 4)
444 ( recho "$UNSET" ; echo after 5)
445 ( recho "${UNSET}" ; echo after 6)
446 ( recho "${#UNSET}" ; echo after 7)
450 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
452 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
454 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
456 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
459 expect $0: 'ABXD: parameter unset'
460 recho ${ABXD:?"parameter unset"}