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*}]} # memory leak
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-
76 echo -n $foo' ' ; echo foo
79 echo -n $foo" " ; echo foo
82 echo -n "$foo " ; echo foo
85 echo -e "$foo\c " ; echo foo
88 echo -e $foo"\c " ; echo foo
90 # make sure backslashes are preserved in front of characters that are not
91 # valid backslash escapes
101 recho ${z:4:3} ${z:${#z}-3:3}
104 recho ${z:4:3} ${z: -3:3}
109 expect '<abcdefghijklmnop>'
112 expect '<abcdefghijklmnop>'
115 set 'ab cd' 'ef' 'gh ij' 'kl mn' 'op'
116 expect '<ab cd> <ef>'
119 expect '<gh ij> <kl mn>'
122 expect '<gh ij> <kl mn> <op>'
125 expect '<ab cd> <ef> <gh ij> <kl mn> <op>'
128 # indirect variable references
129 expect '<abcdefghijklmnop>'
141 expect '<abcdefghijklmnop>'
143 expect '<abcdefghijklmnop>'
152 expect $0: ABX: unbound variable
156 expect $0: '$6: cannot assign in this way'
161 # sed-like variable substitution
179 av=(abcd efgh ijkl mnop qrst uvwx)
188 recho ${av[1]/%ab/xx}
194 recho ${av[1]//??/za}
196 recho ${av[1]//#??/za}
198 recho ${av[1]//%??/za}
200 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
202 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
203 recho ${av[@]/#*/yyy}
204 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
205 recho ${av[@]/%*/yyy}
206 expect '<yyy> <efgh> <ijkl> <mnop> <qrst> <uvwx>'
207 recho ${av[@]/a*/yyy}
208 expect '<abxx> <efxx> <ijxx> <mnxx> <qrxx> <uvxx>'
209 recho ${av[@]/%??/xx}
211 set abcd efgh ijkl mnop qrst uvwx
215 expect '<xxcd> <xxgh> <xxkl> <xxop> <xxst> <xxwx>'
217 expect '<xxcd> <xxgh> <xxkl> <xxop> <xxst> <xxwx>'
223 expect '<zaza> <zaza> <zaza> <zaza> <zaza> <zaza>'
225 expect '<zacd> <zagh> <zakl> <zaop> <zast> <zawx>'
227 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
229 expect '<yyy> <efgh> <ijkl> <mnop> <qrst> <uvwx>'
231 expect '<abcd> <efgh> <ijkl> <mnop> <qrst> <uvwyyy>'
237 # run process substitution tests in a subshell so that syntax errors
238 # caused by a shell not implementing process substitution (e.g., one
239 # built on a NeXT) will not cause the whole test to exit prematurely
240 ${THIS_SH} ./new-exp.sub1
242 expect $0: '${#:-foo}: bad substitution'
244 expect $0: '${#:}: bad substitution'
268 recho ${foo:-"$zbcd"}
290 # this disagrees with sh and ksh, but I think it is right according
293 recho "${foo:-"$z1"}"
296 expect '<ab> <cd> <ef> <gh>'
298 expect '<ab> <cd> <ef> <gh>'
300 expect '<ab> <cd> <ef> <gh>'
307 recho ${foo:-$xxx"$@"}
309 recho "${foo:-$xxx$@}"
311 recho "${foo:-$xxx"$@"}"
329 AB='abcdefghijklmnopqrstuvwxyz'
358 set $'\1' $'\2' $'\177'
380 # out-of-range substrings
388 expect '<./new-exp.tests: -2: substring expression < 0>'
397 # make sure null patterns work
408 # another case that caused a core dump in bash-2.0
409 XPATH=/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin::/usr/bin/X11:/sbin:/usr/sbin
413 xx=(ar as at au av aw ax ay az)
427 set -- ar as at au av aw ax ay az
443 ( recho $9 ; echo after 1)
444 ( recho ${9} ; echo after 2)
445 ( recho $UNSET ; echo after 3)
446 ( recho ${UNSET} ; echo after 4)
447 ( recho "$UNSET" ; echo after 5)
448 ( recho "${UNSET}" ; echo after 6)
449 ( recho "${#UNSET}" ; echo after 7)
453 expect $0: 'ABXD: parameter unset'
454 recho ${ABXD:?"parameter unset"}