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 # sneaky way to replace a newline in a variable value with something else
231 AVAR=$'This\nstring\nhas\nmultiple\nlines.'
234 eval BVAR=\"\${AVAR//$'\n'/-}\"
239 # run process substitution tests in a subshell so that syntax errors
240 # caused by a shell not implementing process substitution (e.g., one
241 # built on a NeXT) will not cause the whole test to exit prematurely
242 ${THIS_SH} ./new-exp1.sub
244 # run the tests of $(<filename) in a subshell to avoid cluttering up
246 ${THIS_SH} ./new-exp2.sub
250 expect $0: '${#:}: bad substitution'
274 recho ${foo:-"$zbcd"}
296 # this disagrees with sh and ksh, but I think it is right according
299 recho "${foo:-"$z1"}"
302 expect '<ab> <cd> <ef> <gh>'
304 expect '<ab> <cd> <ef> <gh>'
306 expect '<ab> <cd> <ef> <gh>'
313 recho ${foo:-$xxx"$@"}
315 recho "${foo:-$xxx$@}"
317 recho "${foo:-$xxx"$@"}"
335 AB='abcdefghijklmnopqrstuvwxyz'
364 set $'\1' $'\2' $'\177'
386 # out-of-range substrings
394 expect '<./new-exp.tests: -2: substring expression < 0>'
403 # make sure null patterns work
414 recho ${xxx//%${zzz}/}
415 recho ${xxx//%${zzz}}
416 recho ${xxx//#${zzz}/}
417 recho ${xxx//#${zzz}}
419 # another case that caused a core dump in bash-2.0
420 XPATH=/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin::/usr/bin/X11:/sbin:/usr/sbin
424 xx=(ar as at au av aw ax ay az)
438 set -- ar as at au av aw ax ay az
454 ( recho $9 ; echo after 1)
455 ( recho ${9} ; echo after 2)
456 ( recho $UNSET ; echo after 3)
457 ( recho ${UNSET} ; echo after 4)
458 ( recho "$UNSET" ; echo after 5)
459 ( recho "${UNSET}" ; echo after 6)
460 ( recho "${#UNSET}" ; echo after 7)
464 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
466 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
468 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
470 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
472 # tests of new prefix expansion ${!prefix*}
473 ${THIS_SH} ./new-exp3.sub
475 # these caused errors and core dumps in versions before bash-2.04
477 echo ${c//${$(($#-1))}/x/}
482 set -- ${@:1:$(($# - 2))}
486 recho ${@:1:$(($# - 2))}
494 # this is an error -- negative expression
496 recho ${@:1:$(($# - 2))}
499 expect $0: 'ABXD: parameter unset'
500 recho ${ABXD:?"parameter unset"}