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 # code to ad-hoc parse arithmetic expressions in substring expansions was
122 # broken until post-2.04
123 base=/home/chet/foo//bar
124 string1=$base/abcabcabc
127 expect '</home/chet/foo//bar/abcabcabc>'
130 expect '<home/chet/foo//bar/abcabcabc>'
134 recho ${string1:(j?1:0):j}
137 recho ${string1:j?1:0:j}
140 recho ${string1:(j?(x?1:0):0):j}
143 recho ${string1:j?(x?1:0):0:j}
145 unset base string1 x j
147 # indirect variable references
148 expect '<abcdefghijklmnop>'
160 expect '<abcdefghijklmnop>'
162 expect '<abcdefghijklmnop>'
171 expect $0: ABX: unbound variable
175 expect $0: '$6: cannot assign in this way'
180 # sed-like variable substitution
198 av=(abcd efgh ijkl mnop qrst uvwx)
207 recho ${av[1]/%ab/xx}
213 recho ${av[1]//??/za}
215 recho ${av[1]/#??/za}
217 recho ${av[1]/%??/za}
219 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
221 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
222 recho ${av[@]/#*/yyy}
223 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
224 recho ${av[@]/%*/yyy}
225 expect '<yyy> <efgh> <ijkl> <mnop> <qrst> <uvwx>'
226 recho ${av[@]/a*/yyy}
227 expect '<abxx> <efxx> <ijxx> <mnxx> <qrxx> <uvxx>'
228 recho ${av[@]/%??/xx}
230 set abcd efgh ijkl mnop qrst uvwx
234 expect '<xxcd> <xxgh> <xxkl> <xxop> <xxst> <xxwx>'
236 expect '<xxcd> <xxgh> <xxkl> <xxop> <xxst> <xxwx>'
242 expect '<zaza> <zaza> <zaza> <zaza> <zaza> <zaza>'
244 expect '<zacd> <zagh> <zakl> <zaop> <zast> <zawx>'
246 expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
248 expect '<yyy> <efgh> <ijkl> <mnop> <qrst> <uvwx>'
250 expect '<abcd> <efgh> <ijkl> <mnop> <qrst> <uvwyyy>'
256 # sneaky way to replace a newline in a variable value with something else
257 AVAR=$'This\nstring\nhas\nmultiple\nlines.'
260 eval BVAR=\"\${AVAR//$'\n'/-}\"
265 # run process substitution tests in a subshell so that syntax errors
266 # caused by a shell not implementing process substitution (e.g., one
267 # built on a NeXT) will not cause the whole test to exit prematurely
268 ${THIS_SH} ./new-exp1.sub
270 # run the tests of $(<filename) in a subshell to avoid cluttering up
272 ${THIS_SH} ./new-exp2.sub
276 expect $0: '${#:}: bad substitution'
300 recho ${foo:-"$zbcd"}
322 # this disagrees with sh and ksh, but I think it is right according
325 recho "${foo:-"$z1"}"
328 expect '<ab> <cd> <ef> <gh>'
330 expect '<ab> <cd> <ef> <gh>'
332 expect '<ab> <cd> <ef> <gh>'
339 recho ${foo:-$xxx"$@"}
341 recho "${foo:-$xxx$@}"
343 recho "${foo:-$xxx"$@"}"
361 AB='abcdefghijklmnopqrstuvwxyz'
390 set $'\1' $'\2' $'\177'
412 # out-of-range substrings
420 # as of bash-4.2, negative LENGTH means offset from the end
431 # make sure null patterns work
442 recho ${xxx//%${zzz}/}
443 recho ${xxx//%${zzz}}
444 recho ${xxx//#${zzz}/}
445 recho ${xxx//#${zzz}}
447 # another case that caused a core dump in bash-2.0
448 XPATH=/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin::/usr/bin/X11:/sbin:/usr/sbin
452 xx=(ar as at au av aw ax ay az)
466 set -- ar as at au av aw ax ay az
482 ( recho $9 ; echo after 1)
483 ( recho ${9} ; echo after 2)
484 ( recho $UNSET ; echo after 3)
485 ( recho ${UNSET} ; echo after 4)
486 ( recho "$UNSET" ; echo after 5)
487 ( recho "${UNSET}" ; echo after 6)
488 ( recho "${#UNSET}" ; echo after 7)
492 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
494 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
496 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
498 recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
500 # tests of new prefix expansion ${!prefix*}
501 ${THIS_SH} ./new-exp3.sub
503 # bug with indirect expansion through bash-2.05b
504 ${THIS_SH} ./new-exp4.sub
506 # these caused errors and core dumps in versions before bash-2.04
508 echo ${c//${$(($#-1))}/x/}
513 set -- ${@:1:$(($# - 2))}
517 recho ${@:1:$(($# - 2))}
525 # this is an error -- negative expression
527 recho ${@:1:$(($# - 2))}
529 XPATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:.:/sbin:/usr/sbin
530 set $( IFS=: ; echo $XPATH )
538 set /full/path/to/x16 /another/full/path
545 ${THIS_SH} ./new-exp5.sub
550 # these had better agree
559 var=(abcde abcfg abchi)
561 # problems with anchoring pattern replacements
562 echo ${var[*]//#abc/foo}
563 echo ${var[*]/#abc/foo}
566 ${THIS_SH} ./new-exp6.sub
568 ${THIS_SH} ./new-exp7.sub
570 ${THIS_SH} ./new-exp8.sub
572 # problems with stray CTLNUL in bash-4.0-alpha
579 expect $0: 'ABXD: parameter unset'
580 recho ${ABXD:?"parameter unset"}