Lines Matching full:echo
1 #!/bin/echo no
26 shxpect "prompt and echo" I$'echo hello\n' O$'hello\n' E"$P"
28 shxpect "redirect err" I$'echo > /dev/full\n' E E"$P" X1
29 shxpect "wait for <(exit)" I$'cat <(echo hello 1>&2)\n' E$'hello\n' E"$P"
32 testing '-c "" exit status 0' '$SH -c "" && echo $?' '0\n' '' ''
33 testing '-c args' "\$SH -c 'echo \$0,\$1,\$2,\$3' one two three four five" \
35 testing '-c args2' "\$SH -c 'echo \${10}' a b c d e f g h i j k l" "k\n" "" ""
37 "$SH -c 'for i in a\"\$@\"b;do echo =\$i=;done;echo \$0' 123 456 789" \
40 "$SH -c 'for i in a\"\$* \$@\"b; do echo =\$i=;done' one two three four five"\
42 testing '-c arg count' "$SH -c 'echo \$#' 9 8 7 6 1 2 3 4" "7\n" "" ""
43 testing 'trailing \' "$SH -c 'echo \'" '\\\n' '' ''
44 testing "trailing \\ in ''" "$SH -c \$'echo \\'one\\\\\\ntwo\\''" \
46 testing 'trailing \ in ""' "$SH -c \$'echo \"one\\\\\\ntwo\"'" 'onetwo\n' \
48 testing 'vanishing \' "$SH -c \$'echo \\\\\\n a'" 'a\n' '' ''
49 testing 'command\ arg' "$SH -c \$'echo\\\\\\n abc'" 'abc\n' '' ''
52 testing 'arg shift' "$SH -c '"'for i in "" 2 1 1 1; do echo $? $1; shift $i; done'"' one two three …
54 testing '(subshell)' '$SH -c "(echo hello)"' 'hello\n' '' ''
55 testing 'syntax' '$SH -c "if true; then echo hello | fi" 2>/dev/null || echo x'\
57 testing 'syntax2' '$SH -c "for;i 0" 2>&1 | { grep -qi syntax && echo yes; }' \
62 testing 'non-absolute $_' "./bash -c 'echo \$_'" './bash\n' '' ''
65 testing 'exec exitval' "$SH -c 'exec echo hello' && echo \$?" "hello\n0\n" "" ""
66 testing 'simple script' '$SH input' 'input\n' 'echo $0' ''
67 testing 'simple script2' '$SH ./input two;echo $?' './input+two\n42\n' \
71 '$SH input 2>/dev/null; [ $? -lt 128 ] && echo pass' 'pass\n' \
73 testing '$LINENO 1' "$SH input" "1\n" 'echo $LINENO' ''
76 echo echo hello > sub/script
82 testing 'IFS $*' "$SH -c 'IFS=xy; echo \"\$*\"' one two tyree" "twoxtyree\n" \
92 '#!/bin/bash\n\nfor i in one two\ndo\n echo $LINENO $i\n echo $LINENO $i\ndone\n' ""
93 testing "eval0" "$SH -c 'eval echo \$*' one two three" "two three\n" "" ""
101 testing 'return code' 'if false; then echo true; fi; echo $?' '0\n' '' ''
102 testing 'return code 2' 'if true; then false; fi; echo $?' '1\n' '' ''
103 testing 'return code 3' 'x=0; while [ $((x++)) -lt 2 ]; do echo $x; done; echo $?' '1\n2\n0\n' '' ''
104 testing 'return code 4' 'false; A=B; echo $?' '0\n' '' ''
106 'l=X;x(){ local l=47; echo $l;unset l; echo l=$l;};x;echo $l' '47\nl=\nX\n' \
108 testing 'escape passthrough' 'echo -e "a\nb\nc\td"' 'a\nb\nc\td\n' '' ''
110 testing 'trailing $ is literal' 'echo $' '$\n' '' ''
111 testing 'work after HERE' $'cat<<0;echo hello\npotato\n0' 'potato\nhello\n' '' ''
120 testing '<<""' $'cat<<"";echo hello\npotato\n\necho huh' 'potato\nhello\nhuh\n'\
127 testing 'HERE straddle' $'cat<<EOF;if true\nhello\nEOF\nthen echo also; fi' \
133 ln -s "$(which echo)" echo2
137 testing 'prefix assignment is local' '{ echo $ABC; } {ABC}</dev/null; echo $3'\
139 testing 'double quotes' 'echo \x "\x" "\\" "\$" "\`"' 'x \x \ $ `\n' '' ''
140 testing 'quoted line escapes' $'echo "\\\none" \'\\\ntwo\'' 'one \\\ntwo\n' '' ''
141 testing 'escape makes argument' 'echo \ | wc -c' '2\n' '' ''
143 # TODO testing 'empty +() is literal' 'echo +()' '+()\n' '' ''
145 # shxpect "EOF" I$'<<EOF;echo hello'
146 shxpect 'queued work after HERE' I$'<<0;echo hello\n' E"> " I$'0\n' O$'hello\n'
148 E E"$P" I$'echo $_\n' O$'hello\n'
150 E E"$P" I$'echo $_\n' O$'hello\n'
152 E E"$P" I$'echo $_\n' O$'hello\n'
154 testing '$_ literal after exec' 'env >/dev/null; echo $_' 'env\n' '' ''
155 shxpect '$_ no path for builtin' I$'true; echo $_\n' O$'true\n'
156 $BROKEN testing 'prefix is local for builtins' 'abc=123; abc=def unset abc; echo $abc' \
159 'SECONDS=123; SECONDS=345 true; echo $SECONDS' '123\n' '' ''
161 testing '$NOTHING clears $_' 'true; $NOTHING; echo $_' '\n' '' ''
163 'ABC=DEF > potato && rm potato && echo $ABC' 'DEF\n' '' ''
164 $BROKEN testing '$_ with functions' 'true; x(){ echo $_;}; x abc; echo $_' \
169 'cd one/two/three && mv ../../../{one,four} && cd .. && echo ${PWD: -9:9}' \
173 testing "smoketest" "echo hello" "hello\n" "" ""
174 testing "assignment" 'x=y; echo $x' 'y\n' '' ''
175 testing "+= assignment" 'x+=abc; y=def; y+=$x; echo $y' 'defabc\n' '' ''
176 testing "eval" "eval echo hello" "hello\n" "" ""
177 testing "eval2" "eval 'echo hello'; echo $?" "hello\n0\n" "" ""
178 testing "eval3" 'X="echo hello"; eval "$X"' "hello\n" "" ""
180 NOSPACE=1 testing "eval5" 'eval echo \" hello \" | wc' ' 1 1 8' "" ""
181 $BROKEN testing 'eval6' $'false; eval \'echo $?\'' '1\n' '' ''
182 testing 'eval7' $'eval \'false\'; echo $?' '1\n' '' ''
183 testing 'eval8' $'false; eval ''; echo $?' '0\n' '' ''
184 $BROKEN testing 'eval9' $'A=echo; false; eval \'$A $?\'' '1\n' '' ''
185 testing "exec" "exec echo hello" "hello\n" "" ""
186 testing "exec2" "exec echo hello; echo $?" "hello\n" "" ""
189 testing "semicolon" "echo one;echo two" "one\ntwo\n" "" ""
190 testing "simple pipe" "echo hello | cat" "hello\n" "" ""
191 testing "&&" "true && echo hello" "hello\n" "" ""
192 testing "&&2" "false && echo hello" "" "" ""
193 testing "||" "true || echo hello" "" "" ""
194 testing "||2" "false || echo hello" "hello\n" "" ""
195 testing "&& ||" "true && false && potato || echo hello" "hello\n" "" ""
196 testing "&& after function" "x(){ false;};x && echo yes" "" "" ""
197 testing "|| after function" "x(){ false;};x || echo yes" "yes\n" "" ""
202 testing "redir2" "echo blah >out; cat out" "blah\n" "" ""
203 testing "redir3" "echo more >>out; cat out" "blah\nmore\n" "" ""
209 testing "redir8" 'echo -n $(<input)' "boing" "boing\n" ""
210 shxpect "redir9" I$'echo hello > out 2>/does/not/exist\n' E E"$P" \
212 testing "redir10" 'echo hello 3<&3' "hello\n" "" ""
213 testing "redir11" 'if :;then echo one;fi {abc}<input; cat <&$abc' \
219 testing "tilde expansion" "echo ~" "$HOME\n" "" ""
220 testing "tilde2" "echo ~/dir" "$HOME/dir\n" "" ""
222 "echo {A{a,b}B{c,d}C}" "{AaBcC} {AaBdC} {AbBcC} {AbBdC}\n" "" ""
223 testing "brackets2" "echo {A{a,b}B{c,d}C,D}" "AaBcC AaBdC AbBcC AbBdC D\n" "" ""
224 testing "brackets3" 'echo {A"b,c"D}' "{Ab,cD}\n" "" ""
225 testing "brackets4" 'echo {A"bc",D}' "Abc D\n" "" ""
226 testing "brackets5" 'echo {A,B,C' "{A,B,C\n" "" ""
227 testing "brackets6" 'echo {{{{A,B},C}D},E}' "{AD} {BD} {CD} E\n" "" ""
228 testing "brackets7" 'echo {{{a,b},c,{d,e}},f}' "a b c d e f\n" "" ""
229 testing "brackets8" 'echo A{a{b,c{B,C}D}d{e,f},g{h,i}j}E' \
231 testing "brackets9" 'echo A{B{C,D}E{N,O},F{G,H}I}J{K,L}M' \
234 testing "bracket+tilde" "echo {~,~root}/pwd" "$HOME/pwd $EXPECT/pwd\n" "" ""
238 testing '${x#prefix}' 'x=abcde; echo ${x#abc}' 'de\n' '' ''
239 testing '${x#short} ${x##long}' 'x=banana; echo ${x#b*n} ${x##b*n}' \
241 toyonly testing '${x#utf8}' 'x=aそcde; echo ${x##a?c}' 'de\n' '' ''
242 testing '${x%y}' 'x=potato; echo ${x%t*o} ${x%%t*o}' 'pota po\n' '' ''
243 testing 'x=${x%y}' 'x=potato; x=${x%t*o}; echo $x' 'pota\n' '' ''
244 testing '${x%glob}' 'x=abc-def; echo ${x%-*f} ${x-*c}' 'abc abc-def\n' '' ''
245 testing 'x=${x//y}' 'x=potato; x=${x//ta}; echo $x' 'poto\n' '' ''
246 testing '${x^y}' 'x=aaaaa; echo ${x^a}' 'Aaaaa\n' '' ''
247 testing '${x^^y}' 'x=abccdec; echo ${x^^c}; x=abcdec; echo ${x^^c}' \
249 testing '${x,y}' 'x=BBB; echo ${x,B}' 'bBB\n' '' ''
250 testing '${x,,y}' 'x=POTATO; echo ${x,,} ${x,,?} ${x,,*} ${x,,T}' \
255 testing 'wildcards' 'echo w[v-x]w w[x-v]w abc/*/ghi' \
258 'touch .abc abc && echo *bc && echo and && echo .*bc' \
261 testing "backtick1" 'x=fred; echo `echo $x`' 'fred\n' "" ""
262 testing "backtick2" 'x=fred; echo `x=y; echo $x`; echo $x' 'y\nfred\n' "" ""
263 testing '$(( ) )' 'echo ab$((echo hello) | tr e x)cd' "abhxllocd\n" "" ""
264 $BROKEN testing '$((x=y)) lifetime' 'a=boing; echo $a $a$((a=4))$a $a' 'boing boing44 4\n' '' ''
266 testing 'quote' "echo \"'\"" "'\n" "" ""
268 testing "math" 'echo $((1+2))' '3\n' '' ''
269 testing "[oldmath]" 'echo $[1+2]' '3\n' '' ''
270 testing "math basic priority" 'echo $((1+2*3**4))' '163\n' '' ''
271 testing "math paren" 'echo $(((1+2)*3))' '9\n' '' ''
272 testing "math spaces" 'echo $(( ( 1 + 2 ) * 7 - 5 ** 2 ))' '-4\n' '' ''
273 testing "((<)) isn't redirect" '((1<2)) </dev/null && echo yes' 'yes\n' '' ''
274 testing "((>)) isn't redirect" '((1>2)) </dev/null || echo yes' 'yes\n' '' ''
275 testing "((not math) )" '((echo hello) )' 'hello\n' '' ''
276 testing "preincrement" 'echo $((++x)); echo $x' '1\n1\n' '' ''
277 testing "preincrement vs prefix plus" 'echo $((+++x)); echo $x' '1\n1\n' '' ''
278 testing "predecrement" 'echo $((--x)); echo $x' '-1\n-1\n' '' ''
279 testing "predecrement vs prefix minus" 'echo $((---x)); echo $x' '1\n-1\n' '' ''
280 testing "minus-minus-minus" 'echo $((x---7)); echo $x' '-7\n-1\n' '' ''
281 testing "x---y is x-- -y not x- --y" 'x=1 y=1; echo $((x---y)) $x $y' '0 0 1\n'\
284 'for((i=0;i<8;i++)); do echo $((i&1?i&2?1:i&4?2:3:4));done' \
286 testing "inherited assignment suppression" 'echo $((0 ? (x++) : 2)); echo $x' \
288 testing "boolean vs logical" 'echo $((2|4&&8))' '1\n' '' ''
290 'echo $((w++||x++&&y++||z++)) w=$w x=$x y=$y z=$z' \
293 'echo $((w++&&x++||y++&&z++)) w=$w x=$x y=$y z=$z' \
295 $BROKEN shxpect '/0' I$'echo $((1/0)); echo here\n' E E"$P" I$'echo $?\n' O$'1\n'
296 $BROKEN shxpect '%0' I$'echo $((1%0)); echo here\n' E E"$P" I$'echo $?\n' O$'1\n'
297 $BROKEN shxpect '/=0' I$'echo $((x/=0)); echo here\n' E E"$P" I$'echo $?\n' O$'1\n'
298 $BROKEN shxpect '%=0' I$'echo $((x%=0)); echo here\n' E E"$P" I$'echo $?\n' O$'1\n'
301 …ng "case" 'for i in A C J B; do case "$i" in A) echo got A ;; B) echo and B ;; C) echo then C ;; *…
303 testing 'case;;&' 'case wow in w?w) echo ok;;& wow) echo no; esac' 'ok\nno\n' \
306 $'case i\n\nin\n\na) echo one\n\n;;\n\ni)\n\necho two\n\n;;\n\nesac' \
309 $'case X in\n X) printf %s "X" || { echo potato;} ;;\nesac' 'X' '' ''
311 'false && for i in a b c; do echo $i; done || echo no' 'no\n' '' ''
312 testing "continue" 'for i in a b c; do for j in d e f; do echo $i $j; continue 2; done; done' \
315 'while X=$(($X+1)); do echo $X; done | while read i; do echo $i; done | head -n 5' \
320 testing "expand" 'echo $PWD' "$(pwd)\n" "" ""
321 testing "expand2" 'echo "$PWD"' "$(pwd)\n" "" ""
322 testing "expand3" 'echo "$"PWD' '$PWD\n' "" ""
323 testing "expand4" 'P=x; echo "$P"WD' 'xWD\n' "" ""
324 testing "dequote" "echo one 'two' ''three 'fo'ur '\\'" \
327 testing "leading variable assignment" 'abc=def env | grep ^abc=; echo $abc' \
330 "abc=def ghi=jkl env | egrep '^(abc|ghi)=' | sort; echo \$abc \$ghi" \
333 'abc=def; abc=ghi echo $abc' "def\n" "" ""
334 testing "leading assignment space" 'X="abc def"; Y=$X; echo "$Y"' \
337 'chicken() { X="$@"; }; chicken a b c d e; echo "$X"' 'a b c d e\n' '' ''
339 "{ 1blah=123 echo hello;} 2>/dev/null || echo no" "no\n" "" ""
341 "blah=123 echo hello > walrus && ls walrus" "walrus\n" "" ""
344 testing "{1..5}" "echo {1..5}" "1 2 3 4 5\n" "" ""
345 testing "{5..1}" "echo {5..1}" "5 4 3 2 1\n" "" ""
346 testing "{5..1..2}" "echo {5..1..2}" "5 3 1\n" "" ""
347 testing "{a..z..-3}" "echo {a..z..-3}" "a d g j m p s v y\n" "" ""
351 '{ sed s/ll/xx/ POIT; }& echo hello > POIT; wait && echo yes' \
358 $BROKEN testing 'background variable assignment' 'X=x; X=y & echo $X' 'x\n' '' ''
360 #$ IFS=x X=xyxz; for i in abc${X}def; do echo =$i=; done
366 … for i in $A $B $C $D L$A L$B L$C L$D $A= $B= $C= $D= L$A= L$B= L$C= L$D=; do echo -n {$i}; done' \
369 'A=" abc def "; for i in ""$A""; do echo =$i=; done' \
372 'A=" abc def "; for i in """"$A""; do echo =$i=; done' \
375 'A=" abc def "; for i in ""x""$A""; do echo =$i=; done' \
378 testing "IFS" 'IFS=x; A=abx; echo -n "$A"' "abx" "" ""
379 testing "IFS2" 'IFS=x; A=abx; echo -n $A' "ab" "" ""
380 testing "IFS3" 'IFS=x; echo "$(echo abx)"' "abx\n" "" ""
381 testing "IFS4" 'IFS=x; echo $(echo abx)y' "ab y\n" "" ""
382 testing "IFS5" 'IFS=xy; for i in abcxdefyghi; do echo =$i=; done' \
384 testing "curly bracket whitespace" 'for i in {$,} ""{$,}; do echo ="$i"=; done'\
387 testing 'empty $! is blank' 'echo $!' "\n" "" ""
388 $BROKEN testing '$! = jobs -p' 'true & [ $(jobs -p) = $! ] && echo yes' "yes\n" "" ""
390 testing '$*' 'cc(){ for i in $*;do echo =$i=;done;};cc "" "" "" "" ""' \
392 testing '$*2' 'cc(){ for i in "$*";do echo =$i=;done;};cc ""' \
395 'cc(){ for i in "$*";do echo =$i=;done;};cc "" ""' "= =\n" "" ""
397 'cc() { echo ="$*"=; for i in =$*=; do echo -$i-; done;}; cc "" ""; echo and; cc ""' \
399 testing 'really?' 'cc() { for i in $*; do echo -$i-; done;}; cc "" "" ""' \
401 testing 'Sigh.' 'cc() { echo =$1$2=;}; cc "" ""' "==\n" "" ""
402 testing '$*4' 'cc(){ for i in "$*";do echo =$i=;done;};cc "" "" "" "" ""' \
404 testing '$*5' 'cc(){ for i in "$*";do echo =$i=;done;};cc "" "abc" ""' \
409 'IFS=x; cc(){ for i in $*; do echo =$i=;done;};cc xabcxx' \
411 testing '$@' 'cc(){ for i in "$@";do echo =$i=;done;};cc "" "" "" "" ""' \
413 testing "IFS10" 'IFS=bcd; A=abcde; for i in $A; do echo =$i=; done' \
416 'IFS=x; chicken() { for i in $@$@; do echo =$i=; done;}; chicken one "" abc dxf ghi' \
418 testing "IFS12" 'IFS=3;chicken(){ return 3;}; chicken;echo 3$?3' '3 3\n' "" ""
421 … for i in $A $B $C $D L$A L$B L$C L$D $A= $B= $C= $D= L$A= L$B= L$C= L$D=; do echo -n {$i}; done' \
424 $BROKEN testing "! isn't special" "echo !" "!\n" "" ""
425 testing "! by itself" '!; echo $?' "1\n" "" ""
426 testing "! true" '! true; echo $?' "1\n" "" ""
427 testing "! ! true" '! ! true; echo $?' "0\n" "" ""
428 testing "! syntax err" '! echo 2>/dev/null < doesnotexist; echo $?' "0\n" "" ""
431 testing "case quoting" 'case a in "a") echo hello;; esac' 'hello\n' "" ""
433 testing "subshell splitting" 'for i in $(true); do echo =$i=; done' "" "" ""
434 testing "subshell split 2" 'for i in $(echo "one two thr"); do echo =$i=; done'\
438 testing "assignment nosplit" 'X="one two"; Y=$X; echo $Y' "one two\n" "" ""
440 'chicken() { for i in a"$@"b;do echo =$i=;done;}; chicken 123 456 789' \
442 testing "assignment nosplit2" 'pop(){ X="$@";};pop one two three; echo $X' \
446 # 'VAR=12345 echo ${VAR}a' "a\n" "" ""
448 # 'BLAH=abcdefghi; echo ${BLAH: 1 : 3 }' "bcd\n" "" ""
450 testing "subshell exit err" '(exit 42); echo $?' "42\n" "" ""
453 #testing 'exec and $$' testing 'echo $$;exec readlink /proc/self'
457 '(exec readlink /proc/self/exe);echo hello' "$X\nhello\n" "" ""
459 "{ exec readlink /proc/self/exe;};echo hi" "$X\n" "" ""
462 '{ echo one; echo two ; } | tee blah.txt; wc blah.txt' \
465 '(echo two;echo three)|tee blah.txt;wc blah.txt' \
468 'echo hello | (read i <input; echo $i; read i; echo $i)' \
471 $BROKEN testing "\$''" $'echo $\'abc\\\'def\\nghi\'' "abc'def\nghi\n" '' ''
472 testing "shift shift" 'shift; shift; shift; echo $? hello' "1 hello\n" "" ""
473 testing 'search cross $*' 'chicken() { echo ${*/b c/ghi}; }; chicken a b c d' \
475 testing 'eval $IFS' 'IFS=x; X=x; eval abc=a${X}b 2>/dev/null; echo $abc' \
477 $BROKEN testing '${@:3:5}' 'chicken() { for i in "${@:3:5}"; do echo =$i=; done; } ; chicken ab cd …
479 $BROKEN testing '${*:3:5}' 'chicken() { for i in "${*:3:5}"; do unset IFS; echo =$i=; done; } ; IFS…
481 testing 'sequence check' 'IFS=x; X=abxcd; echo ${X/bxc/g}' 'agd\n' '' ''
484 #txpect "backtick0" "$SS" "E$P" 'IX=fred; echo `echo \\\\$x`'$'\n' 'Ofred' "E$P" X0
485 #txpect "backtick1" "$SS" "E$P" 'IX=fred; echo `echo $x`'$'\n' 'Ofred'$'\n' "E$P" X0
486 #txpect "backtick2" "$SS" "E$P" 'IX=fred; echo `x=y; echo $x`' $'Oy\n' "E$P" X0
488 shxpect '${ with newline' I$'HELLO=abc; echo ${HELLO/b/\n' E"> " I$'}\n' O$'a c\n'
511 testing '${var}' 'X=abcdef; echo ${X}' 'abcdef\n' '' ''
512 testing '${#}' 'X=abcdef; echo ${#X}' "6\n" "" ""
513 testing 'empty ${}' '{ echo ${};} 2>&1 | grep -o bad' 'bad\n' '' ''
514 $BROKEN shxpect 'empty ${} syntax err abort' I$'echo ${}; echo hello\n' \
515 E I$'echo and\n' O$'and\n'
516 $BROKEN testing '${$b}' '{ echo ${$b};} 2>&1 | grep -o bad' 'bad\n' '' ''
517 testing '${!PATH*}' 'echo ${!PATH*}' 'PATH\n' '' ''
518 testing '${!PATH@}' 'echo ${!PATH@}' 'PATH\n' '' ''
519 #testing '${!PATH[@]}' 'echo ${!PATH[@]}' '0\n' '' ''
520 testing '${!x}' 'X=abcdef Y=X; echo ${!Y}' 'abcdef\n' '' ''
521 testing '${!x@}' 'ABC=def; def=ghi; echo ${!ABC@}' 'ABC\n' '' ''
522 $BROKEN testing '${!x} err' '{ X=abcdef Y=X:2; echo ${!Y}; echo bang;} 2>/dev/null' \
524 testing '${!x*}' 'abcdef=1 abc=2 abcq=; echo "${!abc@}" | tr " " \\n | sort' \
526 testing '${!x*} none' 'echo "${!abc*}"' '\n' '' ''
527 $BROKEN testing '${!x*} err' '{ echo "${!abc*x}"; echo boing;} 2>/dev/null' '' '' ''
529 #testing '${!none@Q}' 'echo ${X@Q} ${!X@Q}; X=ABC; echo ${!X@Q}' '\n\n' '' ''
530 $BROKEN testing '${!x@Q}' 'ABC=123 X=ABC; echo ${!X@Q}' "'123'\n" '' ''
531 $BROKEN testing '${#@Q}' 'echo ${#@Q}' "'0'\n" '' ''
532 $BROKEN testing '${!*}' 'xx() { echo ${!*};}; fruit=123; xx fruit' '123\n' '' ''
533 $BROKEN testing '${!*} indirect' 'xx() { echo ${!a@Q};}; a=@; xx one two three' \
536 '{ ABC=def; def=ghi; echo ${!ABC@ }; } 2>&1 | grep -o bad' 'bad\n' '' ''
538 #testing '${!x@ } no match no err' 'echo ${!ABC@ }def' 'def\n' '' ''
539 $BROKEN testing '${!x@ } no match no err2' 'ABC=def; echo ${!ABC@ }ghi' 'ghi\n' '' ''
540 toyonly testing '${#x::}' 'ABC=abcdefghijklmno; echo ${#ABC:1:2}' '5\n' '' ''
542 testing '$""' 'ABC=def; echo $"$ABC"' 'def\n' '' ''
543 testing '"$""" does not nest' 'echo "$"abc""' '$abc\n' '' ''
544 $BROKEN testing '${\}}' 'ABC=ab}cd; echo ${ABC/\}/x}' 'abxcd\n' '' ''
545 testing 'bad ${^}' '{ echo ${^};} 2>&1 | grep -o bad' 'bad\n' '' ''
546 shxpect '${:} empty len is err' I$'ABC=def; echo ${ABC:}\n' RE'ABC' X
547 testing '${::} both empty=0' 'ABC=def; echo ${ABC::}' '\n' '' ''
548 testing '${::} first empty' 'ABC=def; echo ${ABC: : 2 }' 'de\n' '' ''
549 testing '${::} second empty' 'ABC=def; echo ${ABC: 2 : }' '\n' '' ''
550 testing '${:}' 'ABC=def; echo ${ABC:1}' 'ef\n' '' ''
551 testing '${a: }' 'ABC=def; echo ${ABC: 1}' 'ef\n' '' ''
552 $BROKEN testing '${a :}' 'ABC=def; { echo ${ABC :1};} 2>&1 | grep -o bad' 'bad\n' '' ''
553 testing '${::}' 'ABC=defghi; echo ${ABC:1:2}' 'ef\n' '' ''
554 testing '${: : }' 'ABC=defghi; echo ${ABC: 1 : 2 }' 'ef\n' '' ''
556 'ABC=defghi:1:2; ( echo ${!ABC};) 2>input; [ -s input ] && echo yes' \
558 testing '${::-}' 'ABC=defghi; echo ${ABC:1:-2}' 'efg\n' '' ''
559 testing '${:-:-}' 'ABC=defghi; echo ${ABC:-3:2}' 'defghi\n' '' ''
560 testing '${:-:-}2' 'echo ${ABC:-3:2}' '3:2\n' '' ''
561 testing '${: -:}' 'ABC=defghi; echo ${ABC: -3:2}' 'gh\n' '' ''
562 testing '${@%}' 'chicken() { for i in "${@%abc}"; do echo "=$i="; done;}; chicken 1abc 2abc 3abc' '…
563 testing '${*%}' 'chicken() { for i in "${*%abc}"; do echo "=$i="; done;}; chicken 1abc 2abc 3abc' '…
564 $BROKEN testing '${@@Q}' 'xx() { echo "${@@Q}"; }; xx one two three' \
567 shxpect '${/newline/}' I$'x=$\'\na\';echo ${x/\n' E'> ' I$'/b}\n' O$'ba\n' E'> '
569 shxpect 'line continuation' I$'echo "hello" \\\n' E'> ' I$'> blah\n' E"$P" \
571 shxpect 'line continuation2' I$'echo ABC\\\n' E'> ' I$'DEF\n' O$'ABCDEF\n'
573 testing "line continuation4" $'if true | \\\n(true);then echo true;fi' 'true\n' '' ''
574 $BROKEN testing "line continuation5" $'XYZ=xyz; echo "abc$\\\nXYZ"' 'abcxyz\n' '' ''
577 $BROKEN testing 'SECONDS' 'readonly SECONDS=41; sleep 1; echo $SECONDS' '42\n' '' ''
578 # testing 'SECONDS2' 'readonly SECONDS; SECONDS=0; echo $SECONDS' '' '' '' #bash!
579 $BROKEN testing 'SECONDS2' 'SECONDS=123+456; echo $SECONDS' '0\n' '' '' #bash!!
580 testing '$LINENO 2' $'echo $LINENO\necho $LINENO' '1\n2\n' '' ''
581 testing '$EUID' 'echo $EUID' "$(id -u)\n" '' ''
582 testing '$UID' 'echo $UID' "$(id -ur)\n" '' ''
585 '{ readonly abc=123;abc=def echo hello; echo $?;} 2>output; grep -o readonly output' \
588 …'readonly boink=123; export boink; { boink=234 env | grep ^boink=;} 2>/dev/null; echo $?' 'boink=1…
590 'readonly i; for i in one two three; do echo $i; done 2>/dev/null; echo $?' \
593 'readonly i; echo hello 2>/dev/null {i}</dev/null; echo $?' '1\n' '' ''
594 testing '$_ 1' 'echo walrus; echo $_' 'walrus\nwalrus\n' '' ''
595 testing '$_ 2' 'unset _; echo $_' '_\n' '' ''
601 'IFS=xy; ABC=abcywal*sxdef; echo $ABC | tr " " "\n" | sort' \
608 I$'IFS=x; ABC=cxd; for i in +($ABC); do echo =$i=; done\n' \
613 I$'ABC="c?d"; for i in ab+($ABC); do echo =$i=; done\n' \
618 I$'touch "AB[DEF]"; echo AB[+(DEF]) AB[+(DEF)? AB+([DEF)]\n' \
620 I$'X="("; Y=")"; echo AB[+${X}DEF${Y}?\n' O$'AB[DEF]\n'
622 # TODO: syntax error takes out ': ${a?b}; echo $?' (I.E. never runs echo)
624 I$': ${a?b} ${c:=d}\n' E E"$P" I$'echo $?$c\n' O$'1\n'
626 $BROKEN shxpect 'trace redirect' I$'set -x; echo one\n' E$'+ echo one\n'"$P" O$'one\n' \
627 I$'echo two 2>/dev/null\n' O$'two\n' E$'+ echo two\n'"$P" \
628 I$'{ echo three; } 2>/dev/null\n' O$'three\n' E"$P"
629 shxpect 'set -u' I$'set -u; echo $walrus\n' REwalrus X
631 testing 'source file' 'source input' 'hello\n' 'echo hello \\\n' ''
632 testing '. file' '. input' 'hello\n' 'echo hello \\\n' ''
633 testing 'source no newline' 'source input' 'hello \\\n' 'echo hello \\' ''
634 testing 'source continues' 'echo hello; source <(echo false); echo $?' \
636 testing 'source returns' 'source <(echo return 37); echo $?' '37\n' '' ''
638 'for i in one two three; do echo "echo $i" > input; source input; done' \
641 'func() { source input; }; for i in one two three; do echo echo $i > input; func; done' \
644 …'func() { source input; cat <(echo $xx; xx=456; echo $xx); echo $xx;}; echo local xx=123 > input; …
647 'source input 2>/dev/null || echo yes' 'one\nyes\n' \
648 'echo one\necho two; echo |' ''
650 …'func() { echo one; source <(echo -e "echo hello\necho |") 2>/dev/null; echo three;}; func; echo f…
653 'func() { eval "echo one; echo \${?potato}; echo and" 2>/dev/null; echo plus;}; func; echo then' \
656 'cat <(return 0 2>/dev/null; echo $?); echo after' '2\nafter\n' '' ''
657 testing 'return nests' 'y(){ x; return $((3+$?));};x(){ return 5; };y;echo $?' \
660 shxpect "functions need block" I$'x() echo;\n' RE'[Ss]yntax [Ee]rror' X2
662 '{ echo $BASHPID; chicken() { echo $BASHPID;}; chicken;} | sort -u | wc -l' '1\n' '' ''
664 '{ echo $BASHPID; chicken() ( echo $BASHPID;); chicken;} | sort -u | wc -l' '2\n' '' ''
666 'func() if true; then echo hello; fi; echo one; func; echo two' \
669 'function func if true; then echo hello; fi; echo one; func; echo two' \
672 'function func ( ) if true; then echo hello; fi; echo one; func; echo two' \
675 '( potato() { echo aaa; }; potato )' 'aaa\n' '' ''
677 I$'func() { local potato; echo ${potato?bang}; }; potato=123; func\n' \
678 E E"$P" I$'echo $?\n' O$'1\n'
680 'x() { local RANDOM=potato; echo $RANDOM;};x;echo -e "$RANDOM\n$RANDOM"|wc -l'\
684 '{ echo $$; (echo $$) } | sort -u | wc -l' "1\n" "" ""
686 '{ echo $PPID; (echo $PPID) } | sort -u | wc -l' "1\n" "" ""
688 '{ echo $BASHPID; (echo $BASHPID) } | sort -u | wc -l' "2\n" "" ""
696 $BROKEN testing '$!' '{ echo $BASHPID & echo $!; echo ${!};} | sort -u | wc -l' '1\n' \
700 I$'false\n' E"$P" I$'\n' E"$P" I$'echo $?\n' O$'1\n'
701 testing 'NOP line clears $?' 'false;$NOTHING;echo $?' '0\n' '' ''
702 $BROKEN testing 'run "$@"' 'false;"$@";echo $?' '0\n' '' ''
705 testing '[[split1]]' 'A="1 -lt 2"; [[ $A ]] && echo yes' 'yes\n' '' ''
706 testing '[[split2]]' 'A="2 -lt 1"; [[ $A ]] && echo yes' 'yes\n' '' ''
708 'A="2 -lt 1"; [[ -e $A ]] && echo one; touch "$A" && [[ -e $A ]] && echo two'\
712 '[[ $(cat) == "a b" ]] <<< "a b" > potato && rm potato && echo ok' \
715 '[[ $(cat) == "a b" ]] < <(echo a b) > potato && rm potato && echo ok' \
718 testing '[[1>2]] is not a redirect' '[[ 1 >2 ]] || [ -e 2 ] || echo yup' \
721 '[[ 1 >0 ]] && { [ -e 2 ] || echo yup; }' 'yup\n' '' ''
722 testing '[[1<2]] is alphabetical, not numeric' '[[ 123 < 19 ]] && echo yes' \
724 testing '[[~]]' '[[ ~ == $HOME ]] && echo yes' 'yes\n' '' ''
728 $'echo -n "$(echo "hello $(eval $\'echo -\\\\\\ne \\\'world\\n \\\'\')")"' \
731 $'echo $\'$(abc\'' '$(abc\n' '' ''
734 'if $NONE; then echo hello; fi' 'hello\n' '' ''
740 # ./bash -c 'echo $_' prints $BASH, but PATH search shows path? Hmmm...
769 # does not match: ./sh -c 'echo {a..Z}' becomes a ` _ ^ ] \ [ Z
797 # backslash not discarded: echo "abc\"def"
809 # touch 'AB[DEF]'; echo AB[+(DEF]) AB[+(DEF)?