• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# $MirOS: src/bin/mksh/check.t,v 1.812 2019/03/01 16:17:29 tg Exp $
2# -*- mode: sh -*-
3#-
4# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5#	      2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018,
6#	      2019
7#	mirabilos <m@mirbsd.org>
8#
9# Provided that these terms and disclaimer and all copyright notices
10# are retained or reproduced in an accompanying document, permission
11# is granted to deal in this work without restriction, including un‐
12# limited rights to use, publicly perform, distribute, sell, modify,
13# merge, give away, or sublicence.
14#
15# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
16# the utmost extent permitted by applicable law, neither express nor
17# implied; without malicious intent or gross negligence. In no event
18# may a licensor, author or contributor be held liable for indirect,
19# direct, other damage, loss, or other issues arising in any way out
20# of dealing in the work, even if advised of the possibility of such
21# damage or existence of a defect, except proven that it results out
22# of said person’s immediate fault when using the work as intended.
23#-
24# You may also want to test IFS with the script at
25# http://www.research.att.com/~gsf/public/ifs.sh
26#
27# More testsuites at:
28# http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain
29#
30# Integrated testsuites from:
31# (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
32
33expected-stdout:
34	@(#)MIRBSD KSH R57 2019/03/01
35description:
36	Check base version of full shell
37stdin:
38	echo ${KSH_VERSION%%' +'*}
39name: KSH_VERSION
40category: !shell:legacy-yes
41---
42expected-stdout:
43	@(#)LEGACY KSH R57 2019/03/01
44description:
45	Check base version of legacy shell
46stdin:
47	echo ${KSH_VERSION%%' +'*}
48name: KSH_VERSION-legacy
49category: !shell:legacy-no
50---
51name: KSH_VERSION-ascii
52description:
53	Check that the shell version tag does not include EBCDIC
54category: !shell:ebcdic-yes
55stdin:
56	for x in $KSH_VERSION; do
57		[[ $x = '+EBCDIC' ]] && exit 1
58	done
59	exit 0
60---
61name: KSH_VERSION-ebcdic
62description:
63	Check that the shell version tag includes EBCDIC
64category: !shell:ebcdic-no
65stdin:
66	for x in $KSH_VERSION; do
67		[[ $x = '+EBCDIC' ]] && exit 0
68	done
69	exit 1
70---
71name: KSH_VERSION-binmode
72description:
73	Check that the shell version tag does not include TEXTMODE
74category: !shell:textmode-yes
75stdin:
76	for x in $KSH_VERSION; do
77		[[ $x = '+TEXTMODE' ]] && exit 1
78	done
79	exit 0
80---
81name: KSH_VERSION-textmode
82description:
83	Check that the shell version tag includes TEXTMODE
84category: !shell:textmode-no
85stdin:
86	for x in $KSH_VERSION; do
87		[[ $x = '+TEXTMODE' ]] && exit 0
88	done
89	exit 1
90---
91name: selftest-1
92description:
93	Regression test self-testing
94stdin:
95	echo ${foo:-baz}
96expected-stdout:
97	baz
98---
99name: selftest-2
100description:
101	Regression test self-testing
102env-setup: !foo=bar!
103stdin:
104	echo ${foo:-baz}
105expected-stdout:
106	bar
107---
108name: selftest-3
109description:
110	Regression test self-testing
111env-setup: !ENV=fnord!
112stdin:
113	echo "<$ENV>"
114expected-stdout:
115	<fnord>
116---
117name: selftest-exec
118description:
119	Ensure that the test run directory (default /tmp but can be changed
120	with check.pl flag -T or test.sh $TMPDIR) is not mounted noexec, as
121	we execute scripts from the scratch directory during several tests.
122stdin:
123	print '#!'"$__progname"'\necho tf' >lq
124	chmod +x lq
125	./lq
126expected-stdout:
127	tf
128---
129name: selftest-env
130description:
131	Just output the environment variables set (always fails)
132category: disabled
133stdin:
134	set
135---
136name: selftest-direct-builtin-call
137description:
138	Check that direct builtin calls work
139stdin:
140	ln -s "$__progname" cat || cp "$__progname" cat
141	ln -s "$__progname" echo || cp "$__progname" echo
142	./echo -c 'echo  foo' | ./cat -u
143expected-stdout:
144	-c echo  foo
145---
146name: selftest-pathsep-unix
147description:
148	Check that $PATHSEP is set correctly.
149category: !os:os2
150stdin:
151	PATHSEP=.; export PATHSEP
152	"$__progname" -c 'print -r -- $PATHSEP'
153expected-stdout:
154	:
155---
156name: selftest-pathsep-dospath
157description:
158	Check that $PATHSEP is set correctly.
159category: os:os2
160stdin:
161	PATHSEP=.; export PATHSEP
162	"$__progname" -c 'print -r -- $PATHSEP'
163expected-stdout:
164	;
165---
166name: selftest-tty-absent
167description:
168	Check that a controlling tty is not present as regress:no-ctty was used
169	(if this test fails for you DO NOT PASS regress:no-ctty and fix every
170	other test that fails: why u use it if u haz ctty?)
171category: regress:no-ctty
172env-setup: !ENV=./envf!
173file-setup: file 644 "envf"
174	PS1=X
175arguments: !-i!
176stdin:
177	echo ok
178expected-stdout:
179	ok
180expected-stderr-pattern:
181	/mksh: warning: won't have full job control\nXX/
182---
183name: selftest-tty-present
184description:
185	Check that a controlling tty is present as regress:no-ctty was not used
186need-ctty: yes
187env-setup: !ENV=./envf!
188file-setup: file 644 "envf"
189	PS1=X
190arguments: !-i!
191stdin:
192	echo ok
193expected-stdout:
194	ok
195expected-stderr: !
196	XX
197---
198name: alias-1
199description:
200	Check that recursion is detected/avoided in aliases.
201stdin:
202	alias fooBar=fooBar
203	fooBar
204	exit 0
205expected-stderr-pattern:
206	/fooBar.*not found.*/
207---
208name: alias-2
209description:
210	Check that recursion is detected/avoided in aliases.
211stdin:
212	alias fooBar=barFoo
213	alias barFoo=fooBar
214	fooBar
215	barFoo
216	exit 0
217expected-stderr-pattern:
218	/fooBar.*not found.*\n.*barFoo.*not found/
219---
220name: alias-3
221description:
222	Check that recursion is detected/avoided in aliases.
223stdin:
224	alias Echo='echo '
225	alias fooBar=barFoo
226	alias barFoo=fooBar
227	Echo fooBar
228	unalias barFoo
229	Echo fooBar
230expected-stdout:
231	fooBar
232	barFoo
233---
234name: alias-4
235description:
236	Check that alias expansion isn't done on keywords (in keyword
237	postitions).
238stdin:
239	alias Echo='echo '
240	alias while=While
241	while false; do echo hi ; done
242	Echo while
243expected-stdout:
244	While
245---
246name: alias-5
247description:
248	Check that alias expansion done after alias with trailing space.
249stdin:
250	alias Echo='echo '
251	alias foo='bar stuff '
252	alias bar='Bar1 Bar2 '
253	alias stuff='Stuff'
254	alias blah='Blah'
255	Echo foo blah
256expected-stdout:
257	Bar1 Bar2 Stuff Blah
258---
259name: alias-6
260description:
261	Check that alias expansion done after alias with trailing space.
262stdin:
263	alias Echo='echo '
264	alias foo='bar bar'
265	alias bar='Bar '
266	alias blah=Blah
267	Echo foo blah
268expected-stdout:
269	Bar Bar Blah
270---
271name: alias-7
272description:
273	Check that alias expansion done after alias with trailing space
274	after a keyword.
275stdin:
276	alias X='case '
277	alias Y=Z
278	X Y in 'Y') echo is y ;; Z) echo is z ;; esac
279expected-stdout:
280	is z
281---
282name: alias-8
283description:
284	Check that newlines in an alias don't cause the command to be lost.
285stdin:
286	alias foo='
287
288
289	echo hi
290
291
292
293	echo there
294
295
296	'
297	foo
298expected-stdout:
299	hi
300	there
301---
302name: alias-9
303description:
304	Check that recursion is detected/avoided in aliases.
305	This check fails for slow machines or Cygwin, raise
306	the time-limit clause (e.g. to 7) if this occurs.
307time-limit: 3
308stdin:
309	print '#!'"$__progname"'\necho tf' >lq
310	chmod +x lq
311	PATH=$PWD$PATHSEP$PATH
312	alias lq=lq
313	lq
314	echo = now
315	i=`lq`
316	print -r -- $i
317	echo = out
318	exit 0
319expected-stdout:
320	tf
321	= now
322	tf
323	= out
324---
325name: alias-10
326description:
327	Check that recursion is detected/avoided in aliases.
328	Regression, introduced during an old bugfix.
329stdin:
330	alias foo='print hello '
331	alias bar='foo world'
332	echo $(bar)
333expected-stdout:
334	hello world
335---
336name: alias-11
337description:
338	Check that special argument handling still applies with escaped aliases
339stdin:
340	alias local1='\typeset'
341	alias local2='\\builtin typeset'
342	function fooa {
343		local1 x=$1 y=z
344		print -r -- "$x,$y"
345	}
346	function foob {
347		local2 x=$1 y=z
348		print -r -- "$x,$y"
349	}
350	x=1 y=2; fooa 'bar - baz'
351	x=1 y=2; foob 'bar - baz'
352expected-stdout:
353	bar - baz,z
354	bar - baz,z
355---
356name: alias-12
357description:
358	Something weird from Martijn Dekker
359stdin:
360	alias echo=print
361	x() { echo a; (echo b); x=$(echo c); }
362	typeset -f x
363	alias OPEN='{' CLOSE='};'
364	{ OPEN echo hi1; CLOSE }
365	var=`{ OPEN echo hi2; CLOSE }` && echo "$var"
366	var=$({ OPEN echo hi3; CLOSE }) && echo "$var"
367expected-stdout:
368	x() {
369		\print a
370		( \print b )
371		x=$(\print c )
372	}
373	hi1
374	hi2
375	hi3
376---
377name: arith-compound
378description:
379	Check that arithmetic expressions are compound constructs
380stdin:
381	{ ! (( 0$(cat >&2) )) <<<1; } <<<2
382expected-stderr:
383	1
384---
385name: arith-lazy-1
386description:
387	Check that only one side of ternary operator is evaluated
388stdin:
389	x=i+=2
390	y=j+=2
391	typeset -i i=1 j=1
392	echo $((1 ? 20 : (x+=2)))
393	echo $i,$x
394	echo $((0 ? (y+=2) : 30))
395	echo $j,$y
396expected-stdout:
397	20
398	1,i+=2
399	30
400	1,j+=2
401---
402name: arith-lazy-2
403description:
404	Check that assignments not done on non-evaluated side of ternary
405	operator
406stdin:
407	x=i+=2
408	y=j+=2
409	typeset -i i=1 j=1
410	echo $((1 ? 20 : (x+=2)))
411	echo $i,$x
412	echo $((0 ? (y+=2) : 30))
413	echo $i,$y
414expected-stdout:
415	20
416	1,i+=2
417	30
418	1,j+=2
419---
420name: arith-lazy-3
421description:
422	Check that assignments not done on non-evaluated side of ternary
423	operator and this construct is parsed correctly (Debian #445651)
424stdin:
425	x=4
426	y=$((0 ? x=1 : 2))
427	echo = $x $y =
428expected-stdout:
429	= 4 2 =
430---
431name: arith-lazy-4
432description:
433	Check that preun/postun not done on non-evaluated side of ternary
434	operator
435stdin:
436	(( m = n = 0, 1 ? n++ : m++ ? 2 : 3 ))
437	echo "($n, $m)"
438	m=0; echo $(( 0 ? ++m : 2 )); echo $m
439	m=0; echo $(( 0 ? m++ : 2 )); echo $m
440expected-stdout:
441	(1, 0)
442	2
443	0
444	2
445	0
446---
447name: arith-lazy-5-arr-n
448description: Check lazy evaluation with side effects
449stdin:
450	a=0; echo "$((0&&b[a++],a))"
451expected-stdout:
452	0
453---
454name: arith-lazy-5-arr-p
455description: Check lazy evaluation with side effects
456stdin:
457	a=0; echo "$((0&&(b[a++]),a))"
458expected-stdout:
459	0
460---
461name: arith-lazy-5-str-n
462description: Check lazy evaluation with side effects
463stdin:
464	a=0 b=a++; ((0&&b)); echo $a
465expected-stdout:
466	0
467---
468name: arith-lazy-5-str-p
469description: Check lazy evaluation with side effects
470stdin:
471	a=0 b=a++; ((0&&(b))); echo $a
472expected-stdout:
473	0
474---
475name: arith-lazy-5-tern-l-n
476description: Check lazy evaluation with side effects
477stdin:
478	a=0; echo "$((0?b[a++]:999,a))"
479expected-stdout:
480	0
481---
482name: arith-lazy-5-tern-l-p
483description: Check lazy evaluation with side effects
484stdin:
485	a=0; echo "$((0?(b[a++]):999,a))"
486expected-stdout:
487	0
488---
489name: arith-lazy-5-tern-r-n
490description: Check lazy evaluation with side effects
491stdin:
492	a=0; echo "$((1?999:b[a++],a))"
493expected-stdout:
494	0
495---
496name: arith-lazy-5-tern-r-p
497description: Check lazy evaluation with side effects
498stdin:
499	a=0; echo "$((1?999:(b[a++]),a))"
500expected-stdout:
501	0
502---
503name: arith-ternary-prec-1
504description:
505	Check precedence of ternary operator vs assignment
506stdin:
507	typeset -i x=2
508	y=$((1 ? 20 : x+=2))
509expected-exit: e != 0
510expected-stderr-pattern:
511	/.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/
512---
513name: arith-ternary-prec-2
514description:
515	Check precedence of ternary operator vs assignment
516stdin:
517	typeset -i x=2
518	echo $((0 ? x+=2 : 20))
519expected-stdout:
520	20
521---
522name: arith-prec-1
523description:
524	Prove arithmetic expressions with embedded parameter
525	substitutions cannot be parsed ahead of time
526stdin:
527	a='3 + 4'
528	print 1 $((2 * a)) .
529	print 2 $((2 * $a)) .
530expected-stdout:
531	1 14 .
532	2 10 .
533---
534name: arith-div-assoc-1
535description:
536	Check associativity of division operator
537stdin:
538	echo $((20 / 2 / 2))
539expected-stdout:
540	5
541---
542name: arith-div-byzero
543description:
544	Check division by zero errors out
545stdin:
546	x=$(echo $((1 / 0)))
547	echo =$?:$x.
548expected-stdout:
549	=1:.
550expected-stderr-pattern:
551	/.*divisor/
552---
553name: arith-div-intmin-by-minusone
554description:
555	Check division overflow wraps around silently
556category: int:32
557stdin:
558	echo signed:$((-2147483648 / -1))r$((-2147483648 % -1)).
559	echo unsigned:$((# -2147483648 / -1))r$((# -2147483648 % -1)).
560expected-stdout:
561	signed:-2147483648r0.
562	unsigned:0r2147483648.
563---
564name: arith-div-intmin-by-minusone-64
565description:
566	Check division overflow wraps around silently
567category: int:64
568stdin:
569	echo signed:$((-9223372036854775808 / -1))r$((-9223372036854775808 % -1)).
570	echo unsigned:$((# -9223372036854775808 / -1))r$((# -9223372036854775808 % -1)).
571expected-stdout:
572	signed:-9223372036854775808r0.
573	unsigned:0r9223372036854775808.
574---
575name: arith-assop-assoc-1
576description:
577	Check associativity of assignment-operator operator
578stdin:
579	typeset -i i=1 j=2 k=3
580	echo $((i += j += k))
581	echo $i,$j,$k
582expected-stdout:
583	6
584	6,5,3
585---
586name: arith-mandatory
587description:
588	Passing of this test is *mandatory* for a valid mksh executable!
589category: shell:legacy-no
590stdin:
591	typeset -i sari=0
592	typeset -Ui uari=0
593	typeset -i x=0
594	print -r -- $((x++)):$sari=$uari. #0
595	let --sari --uari
596	print -r -- $((x++)):$sari=$uari. #1
597	sari=2147483647 uari=2147483647
598	print -r -- $((x++)):$sari=$uari. #2
599	let ++sari ++uari
600	print -r -- $((x++)):$sari=$uari. #3
601	let --sari --uari
602	let 'sari *= 2' 'uari *= 2'
603	let ++sari ++uari
604	print -r -- $((x++)):$sari=$uari. #4
605	let ++sari ++uari
606	print -r -- $((x++)):$sari=$uari. #5
607	sari=-2147483648 uari=-2147483648
608	print -r -- $((x++)):$sari=$uari. #6
609	let --sari --uari
610	print -r -- $((x++)):$sari=$uari. #7
611	(( sari = -5 >> 1 ))
612	((# uari = -5 >> 1 ))
613	print -r -- $((x++)):$sari=$uari. #8
614	(( sari = -2 ))
615	((# uari = sari ))
616	print -r -- $((x++)):$sari=$uari. #9
617expected-stdout:
618	0:0=0.
619	1:-1=4294967295.
620	2:2147483647=2147483647.
621	3:-2147483648=2147483648.
622	4:-1=4294967295.
623	5:0=0.
624	6:-2147483648=2147483648.
625	7:2147483647=2147483647.
626	8:-3=2147483645.
627	9:-2=4294967294.
628---
629name: arith-unsigned-1
630description:
631	Check if unsigned arithmetics work
632category: int:32
633stdin:
634	# signed vs unsigned
635	echo x1 $((-1)) $((#-1))
636	# calculating
637	typeset -i vs
638	typeset -Ui vu
639	vs=4123456789; vu=4123456789
640	echo x2 $vs $vu
641	(( vs %= 2147483647 ))
642	(( vu %= 2147483647 ))
643	echo x3 $vs $vu
644	vs=4123456789; vu=4123456789
645	(( # vs %= 2147483647 ))
646	(( # vu %= 2147483647 ))
647	echo x4 $vs $vu
648	# make sure the calculation does not change unsigned flag
649	vs=4123456789; vu=4123456789
650	echo x5 $vs $vu
651	# short form
652	echo x6 $((# vs % 2147483647)) $((# vu % 2147483647))
653	# array refs
654	set -A va
655	va[1975973142]=right
656	va[4123456789]=wrong
657	echo x7 ${va[#4123456789%2147483647]}
658	# make sure multiple calculations don't interfere with each other
659	let '# mca = -4 % -2' ' mcb = -4 % -2'
660	echo x8 $mca $mcb
661expected-stdout:
662	x1 -1 4294967295
663	x2 -171510507 4123456789
664	x3 -171510507 4123456789
665	x4 1975973142 1975973142
666	x5 -171510507 4123456789
667	x6 1975973142 1975973142
668	x7 right
669	x8 -4 0
670---
671name: arith-limit32-1
672description:
673	Check if arithmetics are 32 bit
674category: int:32
675stdin:
676	# signed vs unsigned
677	echo x1 $((-1)) $((#-1))
678	# calculating
679	typeset -i vs
680	typeset -Ui vu
681	vs=2147483647; vu=2147483647
682	echo x2 $vs $vu
683	let vs++ vu++
684	echo x3 $vs $vu
685	vs=4294967295; vu=4294967295
686	echo x4 $vs $vu
687	let vs++ vu++
688	echo x5 $vs $vu
689	let vs++ vu++
690	echo x6 $vs $vu
691expected-stdout:
692	x1 -1 4294967295
693	x2 2147483647 2147483647
694	x3 -2147483648 2147483648
695	x4 -1 4294967295
696	x5 0 0
697	x6 1 1
698---
699name: arith-limit64-1
700description:
701	Check if arithmetics are 64 bit
702category: int:64
703stdin:
704	# signed vs unsigned
705	echo x1 $((-1)) $((#-1))
706	# calculating
707	typeset -i vs
708	typeset -Ui vu
709	vs=9223372036854775807; vu=9223372036854775807
710	echo x2 $vs $vu
711	let vs++ vu++
712	echo x3 $vs $vu
713	vs=18446744073709551615; vu=18446744073709551615
714	echo x4 $vs $vu
715	let vs++ vu++
716	echo x5 $vs $vu
717	let vs++ vu++
718	echo x6 $vs $vu
719expected-stdout:
720	x1 -1 18446744073709551615
721	x2 9223372036854775807 9223372036854775807
722	x3 -9223372036854775808 9223372036854775808
723	x4 -1 18446744073709551615
724	x5 0 0
725	x6 1 1
726---
727name: bksl-nl-ign-1
728description:
729	Check that \newline is not collapsed after #
730stdin:
731	echo hi #there \
732	echo folks
733expected-stdout:
734	hi
735	folks
736---
737name: bksl-nl-ign-2
738description:
739	Check that \newline is not collapsed inside single quotes
740stdin:
741	echo 'hi \
742	there'
743	echo folks
744expected-stdout:
745	hi \
746	there
747	folks
748---
749name: bksl-nl-ign-3
750description:
751	Check that \newline is not collapsed inside single quotes
752stdin:
753	cat << \EOF
754	hi \
755	there
756	EOF
757expected-stdout:
758	hi \
759	there
760---
761name: bksl-nl-ign-4
762description:
763	Check interaction of aliases, single quotes and here-documents
764	with backslash-newline
765	(don't know what POSIX has to say about this)
766stdin:
767	a=2
768	alias x='echo hi
769	cat << "EOF"
770	foo\
771	bar
772	some'
773	x
774	more\
775	stuff$a
776	EOF
777expected-stdout:
778	hi
779	foo\
780	bar
781	some
782	more\
783	stuff$a
784---
785name: bksl-nl-ign-5
786description:
787	Check what happens with backslash at end of input
788	(the old Bourne shell trashes them; so do we)
789stdin: !
790	echo `echo foo\\`bar
791	echo hi\
792expected-stdout:
793	foobar
794	hi
795---
796#
797# Places \newline should be collapsed
798#
799name: bksl-nl-1
800description:
801	Check that \newline is collapsed before, in the middle of, and
802	after words
803stdin:
804	 	 	\
805			 echo hi\
806	There, \
807	folks
808expected-stdout:
809	hiThere, folks
810---
811name: bksl-nl-2
812description:
813	Check that \newline is collapsed in $ sequences
814	(ksh93 fails this)
815stdin:
816	a=12
817	ab=19
818	echo $\
819	a
820	echo $a\
821	b
822	echo $\
823	{a}
824	echo ${a\
825	b}
826	echo ${ab\
827	}
828expected-stdout:
829	12
830	19
831	12
832	19
833	19
834---
835name: bksl-nl-3
836description:
837	Check that \newline is collapsed in $(..) and `...` sequences
838	(ksh93 fails this)
839stdin:
840	echo $\
841	(echo foobar1)
842	echo $(\
843	echo foobar2)
844	echo $(echo foo\
845	bar3)
846	echo $(echo foobar4\
847	)
848	echo `
849	echo stuff1`
850	echo `echo st\
851	uff2`
852expected-stdout:
853	foobar1
854	foobar2
855	foobar3
856	foobar4
857	stuff1
858	stuff2
859---
860name: bksl-nl-4
861description:
862	Check that \newline is collapsed in $((..)) sequences
863	(ksh93 fails this)
864stdin:
865	echo $\
866	((1+2))
867	echo $(\
868	(1+2+3))
869	echo $((\
870	1+2+3+4))
871	echo $((1+\
872	2+3+4+5))
873	echo $((1+2+3+4+5+6)\
874	)
875expected-stdout:
876	3
877	6
878	10
879	15
880	21
881---
882name: bksl-nl-5
883description:
884	Check that \newline is collapsed in double quoted strings
885stdin:
886	echo "\
887	hi"
888	echo "foo\
889	bar"
890	echo "folks\
891	"
892expected-stdout:
893	hi
894	foobar
895	folks
896---
897name: bksl-nl-6
898description:
899	Check that \newline is collapsed in here document delimiters
900	(ksh93 fails second part of this)
901stdin:
902	a=12
903	cat << EO\
904	F
905	a=$a
906	foo\
907	bar
908	EOF
909	cat << E_O_F
910	foo
911	E_O_\
912	F
913	echo done
914expected-stdout:
915	a=12
916	foobar
917	foo
918	done
919---
920name: bksl-nl-7
921description:
922	Check that \newline is collapsed in double-quoted here-document
923	delimiter.
924stdin:
925	a=12
926	cat << "EO\
927	F"
928	a=$a
929	foo\
930	bar
931	EOF
932	echo done
933expected-stdout:
934	a=$a
935	foo\
936	bar
937	done
938---
939name: bksl-nl-8
940description:
941	Check that \newline is collapsed in various 2+ character tokens
942	delimiter.
943	(ksh93 fails this)
944stdin:
945	echo hi &\
946	& echo there
947	echo foo |\
948	| echo bar
949	cat <\
950	< EOF
951	stuff
952	EOF
953	cat <\
954	<\
955	- EOF
956		more stuff
957	EOF
958	cat <<\
959	EOF
960	abcdef
961	EOF
962	echo hi >\
963	> /dev/null
964	echo $?
965	i=1
966	case $i in
967	(\
968	x|\
969	1\
970	) echo hi;\
971	;
972	(*) echo oops
973	esac
974expected-stdout:
975	hi
976	there
977	foo
978	stuff
979	more stuff
980	abcdef
981	0
982	hi
983---
984name: bksl-nl-9
985description:
986	Check that \ at the end of an alias is collapsed when followed
987	by a newline
988	(don't know what POSIX has to say about this)
989stdin:
990	alias x='echo hi\'
991	x
992	echo there
993expected-stdout:
994	hiecho there
995---
996name: bksl-nl-10
997description:
998	Check that \newline in a keyword is collapsed
999stdin:
1000	i\
1001	f true; then\
1002	 echo pass; el\
1003	se echo fail; fi
1004expected-stdout:
1005	pass
1006---
1007#
1008# Places \newline should be collapsed (ksh extensions)
1009#
1010name: bksl-nl-ksh-1
1011description:
1012	Check that \newline is collapsed in extended globbing
1013	(ksh93 fails this)
1014stdin:
1015	xxx=foo
1016	case $xxx in
1017	(f*\
1018	(\
1019	o\
1020	)\
1021	) echo ok ;;
1022	*) echo bad
1023	esac
1024expected-stdout:
1025	ok
1026---
1027name: bksl-nl-ksh-2
1028description:
1029	Check that \newline is collapsed in ((...)) expressions
1030	(ksh93 fails this)
1031stdin:
1032	i=1
1033	(\
1034	(\
1035	i=i+2\
1036	)\
1037	)
1038	echo $i
1039expected-stdout:
1040	3
1041---
1042name: break-1
1043description:
1044	See if break breaks out of loops
1045stdin:
1046	for i in a b c; do echo $i; break; echo bad-$i; done
1047	echo end-1
1048	for i in a b c; do echo $i; break 1; echo bad-$i; done
1049	echo end-2
1050	for i in a b c; do
1051	    for j in x y z; do
1052		echo $i:$j
1053		break
1054		echo bad-$i
1055	    done
1056	    echo end-$i
1057	done
1058	echo end-3
1059	for i in a b c; do echo $i; eval break; echo bad-$i; done
1060	echo end-4
1061expected-stdout:
1062	a
1063	end-1
1064	a
1065	end-2
1066	a:x
1067	end-a
1068	b:x
1069	end-b
1070	c:x
1071	end-c
1072	end-3
1073	a
1074	end-4
1075---
1076name: break-2
1077description:
1078	See if break breaks out of nested loops
1079stdin:
1080	for i in a b c; do
1081	    for j in x y z; do
1082		echo $i:$j
1083		break 2
1084		echo bad-$i
1085	    done
1086	    echo end-$i
1087	done
1088	echo end
1089expected-stdout:
1090	a:x
1091	end
1092---
1093name: break-3
1094description:
1095	What if break used outside of any loops
1096	(ksh88,ksh93 don't print error messages here)
1097stdin:
1098	break
1099expected-stderr-pattern:
1100	/.*break.*/
1101---
1102name: break-4
1103description:
1104	What if break N used when only N-1 loops
1105	(ksh88,ksh93 don't print error messages here)
1106stdin:
1107	for i in a b c; do echo $i; break 2; echo bad-$i; done
1108	echo end
1109expected-stdout:
1110	a
1111	end
1112expected-stderr-pattern:
1113	/.*break.*/
1114---
1115name: break-5
1116description:
1117	Error if break argument isn't a number
1118stdin:
1119	for i in a b c; do echo $i; break abc; echo more-$i; done
1120	echo end
1121expected-stdout:
1122	a
1123expected-exit: e != 0
1124expected-stderr-pattern:
1125	/.*break.*/
1126---
1127name: continue-1
1128description:
1129	See if continue continues loops
1130stdin:
1131	for i in a b c; do echo $i; continue; echo bad-$i ; done
1132	echo end-1
1133	for i in a b c; do echo $i; continue 1; echo bad-$i; done
1134	echo end-2
1135	for i in a b c; do
1136	    for j in x y z; do
1137		echo $i:$j
1138		continue
1139		echo bad-$i-$j
1140	    done
1141	    echo end-$i
1142	done
1143	echo end-3
1144	for i in a b c; do echo $i; eval continue; echo bad-$i ; done
1145	echo end-4
1146expected-stdout:
1147	a
1148	b
1149	c
1150	end-1
1151	a
1152	b
1153	c
1154	end-2
1155	a:x
1156	a:y
1157	a:z
1158	end-a
1159	b:x
1160	b:y
1161	b:z
1162	end-b
1163	c:x
1164	c:y
1165	c:z
1166	end-c
1167	end-3
1168	a
1169	b
1170	c
1171	end-4
1172---
1173name: continue-2
1174description:
1175	See if continue breaks out of nested loops
1176stdin:
1177	for i in a b c; do
1178	    for j in x y z; do
1179		echo $i:$j
1180		continue 2
1181		echo bad-$i-$j
1182	    done
1183	    echo end-$i
1184	done
1185	echo end
1186expected-stdout:
1187	a:x
1188	b:x
1189	c:x
1190	end
1191---
1192name: continue-3
1193description:
1194	What if continue used outside of any loops
1195	(ksh88,ksh93 don't print error messages here)
1196stdin:
1197	continue
1198expected-stderr-pattern:
1199	/.*continue.*/
1200---
1201name: continue-4
1202description:
1203	What if continue N used when only N-1 loops
1204	(ksh88,ksh93 don't print error messages here)
1205stdin:
1206	for i in a b c; do echo $i; continue 2; echo bad-$i; done
1207	echo end
1208expected-stdout:
1209	a
1210	b
1211	c
1212	end
1213expected-stderr-pattern:
1214	/.*continue.*/
1215---
1216name: continue-5
1217description:
1218	Error if continue argument isn't a number
1219stdin:
1220	for i in a b c; do echo $i; continue abc; echo more-$i; done
1221	echo end
1222expected-stdout:
1223	a
1224expected-exit: e != 0
1225expected-stderr-pattern:
1226	/.*continue.*/
1227---
1228name: cd-history
1229description:
1230	Test someone's CD history package (uses arrays)
1231stdin:
1232	# go to known place before doing anything
1233	cd /
1234
1235	alias cd=_cd
1236	function _cd
1237	{
1238		typeset -i cdlen i
1239		typeset t
1240
1241		if [ $# -eq 0 ]
1242		then
1243			set -- $HOME
1244		fi
1245
1246		if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists
1247		then
1248			typeset CDHIST
1249			i=-1
1250			while read -r t			# read directory history file
1251			do
1252				CDHIST[i=i+1]=$t
1253			done <$CDHISTFILE
1254		fi
1255
1256		if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ]
1257		then
1258			_cdins				# insert $PWD into cd history
1259		fi
1260
1261		cdlen=${#CDHIST[*]}			# number of elements in history
1262
1263		case "$@" in
1264		-)					# cd to new dir
1265			if [ "$OLDPWD" = "" ] && ((cdlen>1))
1266			then
1267				'print' ${CDHIST[1]}
1268				'cd' ${CDHIST[1]}
1269				_pwd
1270			else
1271				'cd' $@
1272				_pwd
1273			fi
1274			;;
1275		-l)					# print directory list
1276			typeset -R3 num
1277			((i=cdlen))
1278			while (((i=i-1)>=0))
1279			do
1280				num=$i
1281				'print' "$num ${CDHIST[i]}"
1282			done
1283			return
1284			;;
1285		-[0-9]|-[0-9][0-9])			# cd to dir in list
1286			if (((i=${1#-})<cdlen))
1287			then
1288				'print' ${CDHIST[i]}
1289				'cd' ${CDHIST[i]}
1290				_pwd
1291			else
1292				'cd' $@
1293				_pwd
1294			fi
1295			;;
1296		-*)					# cd to matched dir in list
1297			t=${1#-}
1298			i=1
1299			while ((i<cdlen))
1300			do
1301				case ${CDHIST[i]} in
1302				*$t*)
1303					'print' ${CDHIST[i]}
1304					'cd' ${CDHIST[i]}
1305					_pwd
1306					break
1307					;;
1308				esac
1309				((i=i+1))
1310			done
1311			if ((i>=cdlen))
1312			then
1313				'cd' $@
1314				_pwd
1315			fi
1316			;;
1317		*)					# cd to new dir
1318			'cd' $@
1319			_pwd
1320			;;
1321		esac
1322
1323		_cdins					# insert $PWD into cd history
1324
1325		if [ "$CDHISTFILE" ]
1326		then
1327			cdlen=${#CDHIST[*]}		# number of elements in history
1328
1329			i=0
1330			while ((i<cdlen))
1331			do
1332				'print' -r ${CDHIST[i]}	# update directory history
1333				((i=i+1))
1334			done >$CDHISTFILE
1335		fi
1336	}
1337
1338	function _cdins					# insert $PWD into cd history
1339	{						# meant to be called only by _cd
1340		typeset -i i
1341
1342		((i=0))
1343		while ((i<${#CDHIST[*]}))		# see if dir is already in list
1344		do
1345			if [ "${CDHIST[$i]}" = "$PWD" ]
1346			then
1347				break
1348			fi
1349			((i=i+1))
1350		done
1351
1352		if ((i>22))				# limit max size of list
1353		then
1354			i=22
1355		fi
1356
1357		while (((i=i-1)>=0))			# bump old dirs in list
1358		do
1359			CDHIST[i+1]=${CDHIST[i]}
1360		done
1361
1362		CDHIST[0]=$PWD				# insert new directory in list
1363	}
1364
1365
1366	function _pwd
1367	{
1368		if [ -n "$ECD" ]
1369		then
1370			pwd 1>&6
1371		fi
1372	}
1373	# Start of test
1374	cd /tmp
1375	cd /bin
1376	cd /etc
1377	cd -
1378	cd -2
1379	cd -l
1380expected-stdout:
1381	/bin
1382	/tmp
1383	  3 /
1384	  2 /etc
1385	  1 /bin
1386	  0 /tmp
1387---
1388name: cd-pe
1389description:
1390	Check package for cd -Pe
1391need-pass: no
1392# the mv command fails on Cygwin and z/OS
1393# Hurd aborts the testsuite (permission denied)
1394# QNX does not find subdir to cd into
1395category: !os:cygwin,!os:gnu,!os:msys,!os:nto,!os:os390,!nosymlink
1396file-setup: file 644 "x"
1397	mkdir noread noread/target noread/target/subdir
1398	ln -s noread link
1399	chmod 311 noread
1400	cd -P$1 .
1401	echo 0=$?
1402	bwd=$PWD
1403	cd -P$1 link/target
1404	echo 1=$?,${PWD#$bwd/}
1405	epwd=$($TSHELL -c pwd 2>/dev/null)
1406	# This unexpectedly succeeds on GNU/Linux and MidnightBSD
1407	#echo pwd=$?,$epwd
1408	# expect:	pwd=1,
1409	mv ../../noread ../../renamed
1410	cd -P$1 subdir
1411	echo 2=$?,${PWD#$bwd/}
1412	cd $bwd
1413	chmod 755 noread renamed 2>/dev/null
1414	rm -rf noread link renamed
1415stdin:
1416	export TSHELL="$__progname"
1417	"$__progname" x
1418	echo "now with -e:"
1419	"$__progname" x e
1420expected-stdout:
1421	0=0
1422	1=0,noread/target
1423	2=0,noread/target/subdir
1424	now with -e:
1425	0=0
1426	1=0,noread/target
1427	2=1,noread/target/subdir
1428---
1429name: env-prompt
1430description:
1431	Check that prompt not printed when processing ENV
1432env-setup: !ENV=./foo!
1433file-setup: file 644 "foo"
1434	XXX=_
1435	PS1=X
1436	false && echo hmmm
1437need-ctty: yes
1438arguments: !-i!
1439stdin:
1440	echo hi${XXX}there
1441expected-stdout:
1442	hi_there
1443expected-stderr: !
1444	XX
1445---
1446name: expand-ugly
1447description:
1448	Check that weird ${foo+bar} constructs are parsed correctly
1449stdin:
1450	print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
1451	print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
1452	chmod +x pfn pfs
1453	(echo 1 ${IFS+'}'z}) 2>/dev/null || echo failed in 1
1454	(echo 2 "${IFS+'}'z}") 2>/dev/null || echo failed in 2
1455	(echo 3 "foo ${IFS+'bar} baz") 2>/dev/null || echo failed in 3
1456	(echo -n '4 '; ./pfn "foo ${IFS+"b   c"} baz") 2>/dev/null || echo failed in 4
1457	(echo -n '5 '; ./pfn "foo ${IFS+b   c} baz") 2>/dev/null || echo failed in 5
1458	(echo 6 ${IFS+"}"z}) 2>/dev/null || echo failed in 6
1459	(echo 7 "${IFS+"}"z}") 2>/dev/null || echo failed in 7
1460	(echo 8 "${IFS+\"}\"z}") 2>/dev/null || echo failed in 8
1461	(echo 9 "${IFS+\"\}\"z}") 2>/dev/null || echo failed in 9
1462	(echo 10 foo ${IFS+'bar} baz'}) 2>/dev/null || echo failed in 10
1463	(echo 11 "$(echo "${IFS+'}'z}")") 2>/dev/null || echo failed in 11
1464	(echo 12 "$(echo ${IFS+'}'z})") 2>/dev/null || echo failed in 12
1465	(echo 13 ${IFS+\}z}) 2>/dev/null || echo failed in 13
1466	(echo 14 "${IFS+\}z}") 2>/dev/null || echo failed in 14
1467	u=x; (echo -n '15 '; ./pfs "foo ${IFS+a"b$u{ {"{{\}b} c ${IFS+d{}} bar" ${IFS-e{}} baz; echo .) 2>/dev/null || echo failed in 15
1468	l=t; (echo 16 ${IFS+h`echo -n i ${IFS+$l}h`ere}) 2>/dev/null || echo failed in 16
1469	l=t; (echo 17 ${IFS+h$(echo -n i ${IFS+$l}h)ere}) 2>/dev/null || echo failed in 17
1470	l=t; (echo 18 "${IFS+h`echo -n i ${IFS+$l}h`ere}") 2>/dev/null || echo failed in 18
1471	l=t; (echo 19 "${IFS+h$(echo -n i ${IFS+$l}h)ere}") 2>/dev/null || echo failed in 19
1472	l=t; (echo 20 ${IFS+h`echo -n i "${IFS+$l}"h`ere}) 2>/dev/null || echo failed in 20
1473	l=t; (echo 21 ${IFS+h$(echo -n i "${IFS+$l}"h)ere}) 2>/dev/null || echo failed in 21
1474	l=t; (echo 22 "${IFS+h`echo -n i "${IFS+$l}"h`ere}") 2>/dev/null || echo failed in 22
1475	l=t; (echo 23 "${IFS+h$(echo -n i "${IFS+$l}"h)ere}") 2>/dev/null || echo failed in 23
1476	key=value; (echo -n '24 '; ./pfn "${IFS+'$key'}") 2>/dev/null || echo failed in 24
1477	key=value; (echo -n '25 '; ./pfn "${IFS+"'$key'"}") 2>/dev/null || echo failed in 25	# ksh93: “'$key'”
1478	key=value; (echo -n '26 '; ./pfn ${IFS+'$key'}) 2>/dev/null || echo failed in 26
1479	key=value; (echo -n '27 '; ./pfn ${IFS+"'$key'"}) 2>/dev/null || echo failed in 27
1480	(echo -n '28 '; ./pfn "${IFS+"'"x ~ x'}'x"'}"x}" #') 2>/dev/null || echo failed in 28
1481	u=x; (echo -n '29 '; ./pfs foo ${IFS+a"b$u{ {"{ {\}b} c ${IFS+d{}} bar ${IFS-e{}} baz; echo .) 2>/dev/null || echo failed in 29
1482	(echo -n '30 '; ./pfs ${IFS+foo 'b\
1483	ar' baz}; echo .) 2>/dev/null || (echo failed in 30; echo failed in 31)
1484	(echo -n '32 '; ./pfs ${IFS+foo "b\
1485	ar" baz}; echo .) 2>/dev/null || echo failed in 32
1486	(echo -n '33 '; ./pfs "${IFS+foo 'b\
1487	ar' baz}"; echo .) 2>/dev/null || echo failed in 33
1488	(echo -n '34 '; ./pfs "${IFS+foo "b\
1489	ar" baz}"; echo .) 2>/dev/null || echo failed in 34
1490	(echo -n '35 '; ./pfs ${v=a\ b} x ${v=c\ d}; echo .) 2>/dev/null || echo failed in 35
1491	(echo -n '36 '; ./pfs "${v=a\ b}" x "${v=c\ d}"; echo .) 2>/dev/null || echo failed in 36
1492	(echo -n '37 '; ./pfs ${v-a\ b} x ${v-c\ d}; echo .) 2>/dev/null || echo failed in 37
1493	(echo 38 ${IFS+x'a'y} / "${IFS+x'a'y}" .) 2>/dev/null || echo failed in 38
1494	foo="x'a'y"; (echo 39 ${foo%*'a'*} / "${foo%*'a'*}" .) 2>/dev/null || echo failed in 39
1495	foo="a b c"; (echo -n '40 '; ./pfs "${foo#a}"; echo .) 2>/dev/null || echo failed in 40
1496	(foo() { return 100; }; foo; echo 41 ${#+${#:+${#?}}\ \}\}\}}) 2>/dev/null || echo failed in 41
1497expected-stdout:
1498	1 }z
1499	2 ''z}
1500	3 foo 'bar baz
1501	4 foo b   c baz
1502	5 foo b   c baz
1503	6 }z
1504	7 }z
1505	8 ""z}
1506	9 "}"z
1507	10 foo bar} baz
1508	11 ''z}
1509	12 }z
1510	13 }z
1511	14 }z
1512	15 <foo abx{ {{{}b c d{} bar> <}> <baz> .
1513	16 hi there
1514	17 hi there
1515	18 hi there
1516	19 hi there
1517	20 hi there
1518	21 hi there
1519	22 hi there
1520	23 hi there
1521	24 'value'
1522	25 'value'
1523	26 $key
1524	27 'value'
1525	28 'x ~ x''x}"x}" #
1526	29 <foo> <abx{ {{> <{}b> <c> <d{}> <bar> <}> <baz> .
1527	30 <foo> <b\
1528	ar> <baz> .
1529	32 <foo> <bar> <baz> .
1530	33 <foo 'bar' baz> .
1531	34 <foo bar baz> .
1532	35 <a> <b> <x> <a> <b> .
1533	36 <a\ b> <x> <a\ b> .
1534	37 <a b> <x> <c d> .
1535	38 xay / x'a'y .
1536	39 x' / x' .
1537	40 < b c> .
1538	41 3 }}}
1539---
1540name: expand-unglob-dblq
1541description:
1542	Check that regular "${foo+bar}" constructs are parsed correctly
1543stdin:
1544	u=x
1545	tl_norm() {
1546		v=$2
1547		test x"$v" = x"-" && unset v
1548		(echo "$1 plus norm foo ${v+'bar'} baz")
1549		(echo "$1 dash norm foo ${v-'bar'} baz")
1550		(echo "$1 eqal norm foo ${v='bar'} baz")
1551		(echo "$1 qstn norm foo ${v?'bar'} baz") 2>/dev/null || \
1552		    echo "$1 qstn norm -> error"
1553		(echo "$1 PLUS norm foo ${v:+'bar'} baz")
1554		(echo "$1 DASH norm foo ${v:-'bar'} baz")
1555		(echo "$1 EQAL norm foo ${v:='bar'} baz")
1556		(echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>/dev/null || \
1557		    echo "$1 QSTN norm -> error"
1558	}
1559	tl_paren() {
1560		v=$2
1561		test x"$v" = x"-" && unset v
1562		(echo "$1 plus parn foo ${v+(bar)} baz")
1563		(echo "$1 dash parn foo ${v-(bar)} baz")
1564		(echo "$1 eqal parn foo ${v=(bar)} baz")
1565		(echo "$1 qstn parn foo ${v?(bar)} baz") 2>/dev/null || \
1566		    echo "$1 qstn parn -> error"
1567		(echo "$1 PLUS parn foo ${v:+(bar)} baz")
1568		(echo "$1 DASH parn foo ${v:-(bar)} baz")
1569		(echo "$1 EQAL parn foo ${v:=(bar)} baz")
1570		(echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>/dev/null || \
1571		    echo "$1 QSTN parn -> error"
1572	}
1573	tl_brace() {
1574		v=$2
1575		test x"$v" = x"-" && unset v
1576		(echo "$1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz")
1577		(echo "$1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz")
1578		(echo "$1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz")
1579		(echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>/dev/null || \
1580		    echo "$1 qstn brac -> error"
1581		(echo "$1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz")
1582		(echo "$1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz")
1583		(echo "$1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz")
1584		(echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>/dev/null || \
1585		    echo "$1 QSTN brac -> error"
1586	}
1587	: '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
1588	tl_norm 1 -
1589	tl_norm 2 ''
1590	tl_norm 3 x
1591	tl_paren 4 -
1592	tl_paren 5 ''
1593	tl_paren 6 x
1594	tl_brace 7 -
1595	tl_brace 8 ''
1596	tl_brace 9 x
1597expected-stdout:
1598	1 plus norm foo  baz
1599	1 dash norm foo 'bar' baz
1600	1 eqal norm foo 'bar' baz
1601	1 qstn norm -> error
1602	1 PLUS norm foo  baz
1603	1 DASH norm foo 'bar' baz
1604	1 EQAL norm foo 'bar' baz
1605	1 QSTN norm -> error
1606	2 plus norm foo 'bar' baz
1607	2 dash norm foo  baz
1608	2 eqal norm foo  baz
1609	2 qstn norm foo  baz
1610	2 PLUS norm foo  baz
1611	2 DASH norm foo 'bar' baz
1612	2 EQAL norm foo 'bar' baz
1613	2 QSTN norm -> error
1614	3 plus norm foo 'bar' baz
1615	3 dash norm foo x baz
1616	3 eqal norm foo x baz
1617	3 qstn norm foo x baz
1618	3 PLUS norm foo 'bar' baz
1619	3 DASH norm foo x baz
1620	3 EQAL norm foo x baz
1621	3 QSTN norm foo x baz
1622	4 plus parn foo  baz
1623	4 dash parn foo (bar) baz
1624	4 eqal parn foo (bar) baz
1625	4 qstn parn -> error
1626	4 PLUS parn foo  baz
1627	4 DASH parn foo (bar) baz
1628	4 EQAL parn foo (bar) baz
1629	4 QSTN parn -> error
1630	5 plus parn foo (bar) baz
1631	5 dash parn foo  baz
1632	5 eqal parn foo  baz
1633	5 qstn parn foo  baz
1634	5 PLUS parn foo  baz
1635	5 DASH parn foo (bar) baz
1636	5 EQAL parn foo (bar) baz
1637	5 QSTN parn -> error
1638	6 plus parn foo (bar) baz
1639	6 dash parn foo x baz
1640	6 eqal parn foo x baz
1641	6 qstn parn foo x baz
1642	6 PLUS parn foo (bar) baz
1643	6 DASH parn foo x baz
1644	6 EQAL parn foo x baz
1645	6 QSTN parn foo x baz
1646	7 plus brac foo  c } baz
1647	7 dash brac foo ax{{{}b c d{} baz
1648	7 eqal brac foo ax{{{}b c ax{{{}b} baz
1649	7 qstn brac -> error
1650	7 PLUS brac foo  c } baz
1651	7 DASH brac foo ax{{{}b c d{} baz
1652	7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1653	7 QSTN brac -> error
1654	8 plus brac foo ax{{{}b c d{} baz
1655	8 dash brac foo  c } baz
1656	8 eqal brac foo  c } baz
1657	8 qstn brac foo  c } baz
1658	8 PLUS brac foo  c } baz
1659	8 DASH brac foo ax{{{}b c d{} baz
1660	8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1661	8 QSTN brac -> error
1662	9 plus brac foo ax{{{}b c d{} baz
1663	9 dash brac foo x c x} baz
1664	9 eqal brac foo x c x} baz
1665	9 qstn brac foo x c x} baz
1666	9 PLUS brac foo ax{{{}b c d{} baz
1667	9 DASH brac foo x c x} baz
1668	9 EQAL brac foo x c x} baz
1669	9 QSTN brac foo x c x} baz
1670---
1671name: expand-unglob-unq
1672description:
1673	Check that regular ${foo+bar} constructs are parsed correctly
1674stdin:
1675	u=x
1676	tl_norm() {
1677		v=$2
1678		test x"$v" = x"-" && unset v
1679		(echo $1 plus norm foo ${v+'bar'} baz)
1680		(echo $1 dash norm foo ${v-'bar'} baz)
1681		(echo $1 eqal norm foo ${v='bar'} baz)
1682		(echo $1 qstn norm foo ${v?'bar'} baz) 2>/dev/null || \
1683		    echo "$1 qstn norm -> error"
1684		(echo $1 PLUS norm foo ${v:+'bar'} baz)
1685		(echo $1 DASH norm foo ${v:-'bar'} baz)
1686		(echo $1 EQAL norm foo ${v:='bar'} baz)
1687		(echo $1 QSTN norm foo ${v:?'bar'} baz) 2>/dev/null || \
1688		    echo "$1 QSTN norm -> error"
1689	}
1690	tl_paren() {
1691		v=$2
1692		test x"$v" = x"-" && unset v
1693		(echo $1 plus parn foo ${v+\(bar')'} baz)
1694		(echo $1 dash parn foo ${v-\(bar')'} baz)
1695		(echo $1 eqal parn foo ${v=\(bar')'} baz)
1696		(echo $1 qstn parn foo ${v?\(bar')'} baz) 2>/dev/null || \
1697		    echo "$1 qstn parn -> error"
1698		(echo $1 PLUS parn foo ${v:+\(bar')'} baz)
1699		(echo $1 DASH parn foo ${v:-\(bar')'} baz)
1700		(echo $1 EQAL parn foo ${v:=\(bar')'} baz)
1701		(echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>/dev/null || \
1702		    echo "$1 QSTN parn -> error"
1703	}
1704	tl_brace() {
1705		v=$2
1706		test x"$v" = x"-" && unset v
1707		(echo $1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz)
1708		(echo $1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz)
1709		(echo $1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz)
1710		(echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>/dev/null || \
1711		    echo "$1 qstn brac -> error"
1712		(echo $1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz)
1713		(echo $1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz)
1714		(echo $1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz)
1715		(echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>/dev/null || \
1716		    echo "$1 QSTN brac -> error"
1717	}
1718	: '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
1719	tl_norm 1 -
1720	tl_norm 2 ''
1721	tl_norm 3 x
1722	tl_paren 4 -
1723	tl_paren 5 ''
1724	tl_paren 6 x
1725	tl_brace 7 -
1726	tl_brace 8 ''
1727	tl_brace 9 x
1728expected-stdout:
1729	1 plus norm foo baz
1730	1 dash norm foo bar baz
1731	1 eqal norm foo bar baz
1732	1 qstn norm -> error
1733	1 PLUS norm foo baz
1734	1 DASH norm foo bar baz
1735	1 EQAL norm foo bar baz
1736	1 QSTN norm -> error
1737	2 plus norm foo bar baz
1738	2 dash norm foo baz
1739	2 eqal norm foo baz
1740	2 qstn norm foo baz
1741	2 PLUS norm foo baz
1742	2 DASH norm foo bar baz
1743	2 EQAL norm foo bar baz
1744	2 QSTN norm -> error
1745	3 plus norm foo bar baz
1746	3 dash norm foo x baz
1747	3 eqal norm foo x baz
1748	3 qstn norm foo x baz
1749	3 PLUS norm foo bar baz
1750	3 DASH norm foo x baz
1751	3 EQAL norm foo x baz
1752	3 QSTN norm foo x baz
1753	4 plus parn foo baz
1754	4 dash parn foo (bar) baz
1755	4 eqal parn foo (bar) baz
1756	4 qstn parn -> error
1757	4 PLUS parn foo baz
1758	4 DASH parn foo (bar) baz
1759	4 EQAL parn foo (bar) baz
1760	4 QSTN parn -> error
1761	5 plus parn foo (bar) baz
1762	5 dash parn foo baz
1763	5 eqal parn foo baz
1764	5 qstn parn foo baz
1765	5 PLUS parn foo baz
1766	5 DASH parn foo (bar) baz
1767	5 EQAL parn foo (bar) baz
1768	5 QSTN parn -> error
1769	6 plus parn foo (bar) baz
1770	6 dash parn foo x baz
1771	6 eqal parn foo x baz
1772	6 qstn parn foo x baz
1773	6 PLUS parn foo (bar) baz
1774	6 DASH parn foo x baz
1775	6 EQAL parn foo x baz
1776	6 QSTN parn foo x baz
1777	7 plus brac foo c } baz
1778	7 dash brac foo ax{{{}b c d{} baz
1779	7 eqal brac foo ax{{{}b c ax{{{}b} baz
1780	7 qstn brac -> error
1781	7 PLUS brac foo c } baz
1782	7 DASH brac foo ax{{{}b c d{} baz
1783	7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1784	7 QSTN brac -> error
1785	8 plus brac foo ax{{{}b c d{} baz
1786	8 dash brac foo c } baz
1787	8 eqal brac foo c } baz
1788	8 qstn brac foo c } baz
1789	8 PLUS brac foo c } baz
1790	8 DASH brac foo ax{{{}b c d{} baz
1791	8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1792	8 QSTN brac -> error
1793	9 plus brac foo ax{{{}b c d{} baz
1794	9 dash brac foo x c x} baz
1795	9 eqal brac foo x c x} baz
1796	9 qstn brac foo x c x} baz
1797	9 PLUS brac foo ax{{{}b c d{} baz
1798	9 DASH brac foo x c x} baz
1799	9 EQAL brac foo x c x} baz
1800	9 QSTN brac foo x c x} baz
1801---
1802name: expand-threecolons-dblq
1803description:
1804	Check for a particular thing that used to segfault
1805stdin:
1806	TEST=1234
1807	echo "${TEST:1:2:3}"
1808	echo $? but still living
1809expected-stderr-pattern:
1810	/bad substitution/
1811expected-exit: 1
1812---
1813name: expand-threecolons-unq
1814description:
1815	Check for a particular thing that used to not error out
1816stdin:
1817	TEST=1234
1818	echo ${TEST:1:2:3}
1819	echo $? but still living
1820expected-stderr-pattern:
1821	/bad substitution/
1822expected-exit: 1
1823---
1824name: expand-weird-1
1825description:
1826	Check corner cases of trim expansion vs. $# vs. ${#var} vs. ${var?}
1827stdin:
1828	set 1 2 3 4 5 6 7 8 9 10 11
1829	echo ${#}	# value of $#
1830	echo ${##}	# length of $#
1831	echo ${##1}	# $# trimmed 1
1832	set 1 2 3 4 5 6 7 8 9 10 11 12
1833	echo ${##1}
1834	(exit 0)
1835	echo $? = ${#?} .
1836	(exit 111)
1837	echo $? = ${#?} .
1838expected-stdout:
1839	11
1840	2
1841	1
1842	2
1843	0 = 1 .
1844	111 = 3 .
1845---
1846name: expand-weird-2
1847description:
1848	Check more substitution and extension corner cases
1849stdin:
1850	:& set -C; pid=$$; sub=$!; flg=$-; set -- i; exec 3>x.tmp
1851	#echo "D: !=$! #=$# \$=$$ -=$- ?=$?"
1852	echo >&3 3 = s^${!-word} , ${#-word} , p^${$-word} , f^${--word} , ${?-word} .
1853	echo >&3 4 = ${!+word} , ${#+word} , ${$+word} , ${-+word} , ${?+word} .
1854	echo >&3 5 = s^${!=word} , ${#=word} , p^${$=word} , f^${-=word} , ${?=word} .
1855	echo >&3 6 = s^${!?word} , ${#?word} , p^${$?word} , f^${-?word} , ${??word} .
1856	echo >&3 7 = sl^${#!} , ${##} , pl^${#$} , fl^${#-} , ${#?} .
1857	echo >&3 8 = sw^${%!} , ${%#} , pw^${%$} , fw^${%-} , ${%?} .
1858	echo >&3 9 = ${!!} , s^${!#} , ${!$} , s^${!-} , s^${!?} .
1859	echo >&3 10 = s^${!#pattern} , ${##pattern} , p^${$#pattern} , f^${-#pattern} , ${?#pattern} .
1860	echo >&3 11 = s^${!%pattern} , ${#%pattern} , p^${$%pattern} , f^${-%pattern} , ${?%pattern} .
1861	echo >&3 12 = $# : ${##} , ${##1} .
1862	set --
1863	echo >&3 14 = $# : ${##} , ${##1} .
1864	set -- 1 2 3 4 5
1865	echo >&3 16 = $# : ${##} , ${##1} .
1866	set -- 1 2 3 4 5 6 7 8 9 a b c d e
1867	echo >&3 18 = $# : ${##} , ${##1} .
1868	exec 3>&-
1869	<x.tmp sed \
1870	    -e "s/ pl^${#pid} / PID /g" -e "s/ sl^${#sub} / SUB /g" -e "s/ fl^${#flg} / FLG /g" \
1871	    -e "s/ pw^${%pid} / PID /g" -e "s/ sw^${%sub} / SUB /g" -e "s/ fw^${%flg} / FLG /g" \
1872	    -e "s/ p^$pid / PID /g" -e "s/ s^$sub / SUB /g" -e "s/ f^$flg / FLG /g"
1873expected-stdout:
1874	3 = SUB , 1 , PID , FLG , 0 .
1875	4 = word , word , word , word , word .
1876	5 = SUB , 1 , PID , FLG , 0 .
1877	6 = SUB , 1 , PID , FLG , 0 .
1878	7 = SUB , 1 , PID , FLG , 1 .
1879	8 = SUB , 1 , PID , FLG , 1 .
1880	9 = ! , SUB , $ , SUB , SUB .
1881	10 = SUB , 1 , PID , FLG , 0 .
1882	11 = SUB , 1 , PID , FLG , 0 .
1883	12 = 1 : 1 , .
1884	14 = 0 : 1 , 0 .
1885	16 = 5 : 1 , 5 .
1886	18 = 14 : 2 , 4 .
1887---
1888name: expand-weird-3
1889description:
1890	Check that trimming works with positional parameters (Debian #48453)
1891stdin:
1892	A=9999-02
1893	B=9999
1894	echo 1=${A#$B?}.
1895	set -- $A $B
1896	echo 2=${1#$2?}.
1897expected-stdout:
1898	1=02.
1899	2=02.
1900---
1901name: expand-weird-4
1902description:
1903	Check that tilde expansion is enabled in ${x#~}
1904	and cases that are modelled after it (${x/~/~})
1905stdin:
1906	HOME=/etc
1907	a="~/x"
1908	echo "<${a#~}> <${a#\~}> <${b:-~}> <${b:-\~}> <${c:=~}><$c> <${a/~}> <${a/x/~}> <${a/x/\~}>"
1909expected-stdout:
1910	<~/x> </x> <~> <\~> <~><~> <~/x> <~//etc> <~/~>
1911---
1912name: expand-bang-1
1913description:
1914	Check corner case of ${!?} with ! being var vs. op
1915stdin:
1916	echo ${!?}
1917expected-exit: 1
1918expected-stderr-pattern: /not set/
1919---
1920name: expand-bang-2
1921description:
1922	Check corner case of ${!var} vs. ${var op} with var=!
1923stdin:
1924	echo 1 $! .
1925	echo 2 ${!#} .
1926	echo 3 ${!#[0-9]} .
1927	echo 4 ${!-foo} .
1928	# get an at least three-digit bg pid
1929	while :; do
1930		:&
1931		x=$!
1932		if [[ $x != +([0-9]) ]]; then
1933			echo >&2 "cannot test, pid '$x' not numeric"
1934			echo >&2 report this with as many details as possible
1935			exit 1
1936		fi
1937		[[ $x = [0-9][0-9][0-9]* ]] && break
1938	done
1939	y=${x#?}
1940	t=$!; [[ $t = $x ]]; echo 5 $? .
1941	t=${!#}; [[ $t = $x ]]; echo 6 $? .
1942	t=${!#[0-9]}; [[ $t = $y ]]; echo 7 $? .
1943	t=${!-foo}; [[ $t = $x ]]; echo 8 $? .
1944	t=${!?bar}; [[ $t = $x ]]; echo 9 $? .
1945expected-stdout:
1946	1 .
1947	2 .
1948	3 .
1949	4 foo .
1950	5 0 .
1951	6 0 .
1952	7 0 .
1953	8 0 .
1954	9 0 .
1955---
1956name: expand-number-1
1957description:
1958	Check that positional arguments do not overflow
1959stdin:
1960	echo "1 ${12345678901234567890} ."
1961expected-stdout:
1962	1  .
1963---
1964name: expand-slashes-1
1965description:
1966	Check that side effects in substring replacement are handled correctly
1967stdin:
1968	foo=n1n1n1n2n3
1969	i=2
1970	n=1
1971	echo 1 ${foo//n$((n++))/[$((++i))]} .
1972	echo 2 $n , $i .
1973expected-stdout:
1974	1 [3][3][3]n2n3 .
1975	2 2 , 3 .
1976---
1977name: expand-slashes-2
1978description:
1979	Check that side effects in substring replacement are handled correctly
1980stdin:
1981	foo=n1n1n1n2n3
1982	i=2
1983	n=1
1984	echo 1 ${foo@/n$((n++))/[$((++i))]} .
1985	echo 2 $n , $i .
1986expected-stdout:
1987	1 [3]n1n1[4][5] .
1988	2 5 , 5 .
1989---
1990name: expand-slashes-3
1991description:
1992	Check that we can access the replaced string
1993stdin:
1994	foo=n1n1n1n2n3
1995	echo 1 ${foo@/n[12]/[$KSH_MATCH]} .
1996expected-stdout:
1997	1 [n1][n1][n1][n2]n3 .
1998---
1999name: eglob-bad-1
2000description:
2001	Check that globbing isn't done when glob has syntax error
2002category: !os:cygwin,!os:msys,!os:os2
2003file-setup: file 644 "@(a[b|)c]foo"
2004stdin:
2005	echo @(a[b|)c]*
2006expected-stdout:
2007	@(a[b|)c]*
2008---
2009name: eglob-bad-2
2010description:
2011	Check that globbing isn't done when glob has syntax error
2012	(AT&T ksh fails this test)
2013file-setup: file 644 "abcx"
2014file-setup: file 644 "abcz"
2015file-setup: file 644 "bbc"
2016stdin:
2017	echo [a*(]*)z
2018expected-stdout:
2019	[a*(]*)z
2020---
2021name: eglob-infinite-plus
2022description:
2023	Check that shell doesn't go into infinite loop expanding +(...)
2024	expressions.
2025file-setup: file 644 "abc"
2026time-limit: 3
2027stdin:
2028	echo +()c
2029	echo +()x
2030	echo +(*)c
2031	echo +(*)x
2032expected-stdout:
2033	+()c
2034	+()x
2035	abc
2036	+(*)x
2037---
2038name: eglob-subst-1
2039description:
2040	Check that eglobbing isn't done on substitution results
2041file-setup: file 644 "abc"
2042stdin:
2043	x='@(*)'
2044	echo $x
2045expected-stdout:
2046	@(*)
2047---
2048name: eglob-nomatch-1
2049description:
2050	Check that the pattern doesn't match
2051stdin:
2052	echo 1: no-file+(a|b)stuff
2053	echo 2: no-file+(a*(c)|b)stuff
2054	echo 3: no-file+((((c)))|b)stuff
2055expected-stdout:
2056	1: no-file+(a|b)stuff
2057	2: no-file+(a*(c)|b)stuff
2058	3: no-file+((((c)))|b)stuff
2059---
2060name: eglob-match-1
2061description:
2062	Check that the pattern matches correctly
2063file-setup: file 644 "abd"
2064file-setup: file 644 "acd"
2065file-setup: file 644 "abac"
2066stdin:
2067	echo 1: a+(b|c)d
2068	echo 2: a!(@(b|B))d
2069	echo 3: *(a(b|c))		# (...|...) can be used within X(..)
2070	echo 4: a[b*(foo|bar)]d		# patterns not special inside [...]
2071expected-stdout:
2072	1: abd acd
2073	2: acd
2074	3: abac
2075	4: abd
2076---
2077name: eglob-case-1
2078description:
2079	Simple negation tests
2080stdin:
2081	case foo in !(foo|bar)) echo yes;; *) echo no;; esac
2082	case bar in !(foo|bar)) echo yes;; *) echo no;; esac
2083expected-stdout:
2084	no
2085	no
2086---
2087name: eglob-case-2
2088description:
2089	Simple kleene tests
2090stdin:
2091	case foo in *(a|b[)) echo yes;; *) echo no;; esac
2092	case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
2093	case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
2094	case 'aab[b[ab[a' in *(a|b[)) echo yes;; *) echo no;; esac
2095expected-stdout:
2096	no
2097	yes
2098	no
2099	yes
2100---
2101name: eglob-trim-1
2102description:
2103	Eglobbing in trim expressions...
2104	(AT&T ksh fails this - docs say # matches shortest string, ## matches
2105	longest...)
2106stdin:
2107	x=abcdef
2108	echo 1: ${x#a|abc}
2109	echo 2: ${x##a|abc}
2110	echo 3: ${x%def|f}
2111	echo 4: ${x%%f|def}
2112expected-stdout:
2113	1: bcdef
2114	2: def
2115	3: abcde
2116	4: abc
2117---
2118name: eglob-trim-2
2119description:
2120	Check eglobbing works in trims...
2121stdin:
2122	x=abcdef
2123	echo 1: ${x#*(a|b)cd}
2124	echo 2: "${x#*(a|b)cd}"
2125	echo 3: ${x#"*(a|b)cd"}
2126	echo 4: ${x#a(b|c)}
2127expected-stdout:
2128	1: ef
2129	2: ef
2130	3: abcdef
2131	4: cdef
2132---
2133name: eglob-trim-3
2134description:
2135	Check eglobbing works in trims, for Korn Shell
2136	Ensure eglobbing does not work for reduced-feature /bin/sh
2137stdin:
2138	set +o sh
2139	x=foobar
2140	y=foobaz
2141	z=fooba\?
2142	echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
2143	echo "<${x%ba(r|z)},${y%ba(r|z)}>"
2144	set -o sh
2145	echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
2146	z='foo(bar'
2147	echo "<${z%(*}>"
2148expected-stdout:
2149	<foo,foo,fooba>
2150	<foo,foo>
2151	<foobar,foobaz,fooba>
2152	<foo>
2153---
2154name: eglob-substrpl-1
2155description:
2156	Check eglobbing works in substs... and they work at all
2157stdin:
2158	[[ -n $BASH_VERSION ]] && shopt -s extglob
2159	x=1222321_ab/cde_b/c_1221
2160	y=xyz
2161	echo 1: ${x/2} . ${x/}
2162	echo 2: ${x//2}
2163	echo 3: ${x/+(2)}
2164	echo 4: ${x//+(2)}
2165	echo 5: ${x/2/4}
2166	echo 6: ${x//2/4}
2167	echo 7: ${x/+(2)/4}
2168	echo 8: ${x//+(2)/4}
2169	echo 9: ${x/b/c/e/f}
2170	echo 10: ${x/b\/c/e/f}
2171	echo 11: ${x/b\/c/e\/f}
2172	echo 12: ${x/b\/c/e\\/f}
2173	echo 13: ${x/b\\/c/e\\/f}
2174	echo 14: ${x//b/c/e/f}
2175	echo 15: ${x//b\/c/e/f}
2176	echo 16: ${x//b\/c/e\/f}
2177	echo 17: ${x//b\/c/e\\/f}
2178	echo 18: ${x//b\\/c/e\\/f}
2179	echo 19: ${x/b\/*\/c/x}
2180	echo 20: ${x/\//.}
2181	echo 21: ${x//\//.}
2182	echo 22: ${x///.}
2183	echo 23: ${x/#1/9}
2184	echo 24: ${x//#1/9}
2185	echo 25: ${x/%1/9}
2186	echo 26: ${x//%1/9}
2187	echo 27: ${x//\%1/9}
2188	echo 28: ${x//\\%1/9}
2189	echo 29: ${x//\a/9}
2190	echo 30: ${x//\\a/9}
2191	echo 31: ${x/2/$y}
2192expected-stdout:
2193	1: 122321_ab/cde_b/c_1221 . 1222321_ab/cde_b/c_1221
2194	2: 131_ab/cde_b/c_11
2195	3: 1321_ab/cde_b/c_1221
2196	4: 131_ab/cde_b/c_11
2197	5: 1422321_ab/cde_b/c_1221
2198	6: 1444341_ab/cde_b/c_1441
2199	7: 14321_ab/cde_b/c_1221
2200	8: 14341_ab/cde_b/c_141
2201	9: 1222321_ac/e/f/cde_b/c_1221
2202	10: 1222321_ae/fde_b/c_1221
2203	11: 1222321_ae/fde_b/c_1221
2204	12: 1222321_ae\/fde_b/c_1221
2205	13: 1222321_ab/cde_b/c_1221
2206	14: 1222321_ac/e/f/cde_c/e/f/c_1221
2207	15: 1222321_ae/fde_e/f_1221
2208	16: 1222321_ae/fde_e/f_1221
2209	17: 1222321_ae\/fde_e\/f_1221
2210	18: 1222321_ab/cde_b/c_1221
2211	19: 1222321_ax_1221
2212	20: 1222321_ab.cde_b/c_1221
2213	21: 1222321_ab.cde_b.c_1221
2214	22: 1222321_ab/cde_b/c_1221
2215	23: 9222321_ab/cde_b/c_1221
2216	24: 1222321_ab/cde_b/c_1221
2217	25: 1222321_ab/cde_b/c_1229
2218	26: 1222321_ab/cde_b/c_1221
2219	27: 1222321_ab/cde_b/c_1221
2220	28: 1222321_ab/cde_b/c_1221
2221	29: 1222321_9b/cde_b/c_1221
2222	30: 1222321_ab/cde_b/c_1221
2223	31: 1xyz22321_ab/cde_b/c_1221
2224---
2225name: eglob-substrpl-2
2226description:
2227	Check anchored substring replacement works, corner cases
2228stdin:
2229	foo=123
2230	echo 1: ${foo/#/x}
2231	echo 2: ${foo/%/x}
2232	echo 3: ${foo/#/}
2233	echo 4: ${foo/#}
2234	echo 5: ${foo/%/}
2235	echo 6: ${foo/%}
2236expected-stdout:
2237	1: x123
2238	2: 123x
2239	3: 123
2240	4: 123
2241	5: 123
2242	6: 123
2243---
2244name: eglob-substrpl-3a
2245description:
2246	Check substring replacement works with variables and slashes, too
2247stdin:
2248	HOME=/etc
2249	pfx=/home/user
2250	wd=/home/user/tmp
2251	echo "${wd/#$pfx/~}"
2252	echo "${wd/#\$pfx/~}"
2253	echo "${wd/#"$pfx"/~}"
2254	echo "${wd/#'$pfx'/~}"
2255	echo "${wd/#"\$pfx"/~}"
2256	echo "${wd/#'\$pfx'/~}"
2257expected-stdout:
2258	/etc/tmp
2259	/home/user/tmp
2260	/etc/tmp
2261	/home/user/tmp
2262	/home/user/tmp
2263	/home/user/tmp
2264---
2265name: eglob-substrpl-3b
2266description:
2267	More of this, bash fails it (bash4 passes)
2268stdin:
2269	HOME=/etc
2270	pfx=/home/user
2271	wd=/home/user/tmp
2272	echo "${wd/#$(echo /home/user)/~}"
2273	echo "${wd/#"$(echo /home/user)"/~}"
2274	echo "${wd/#'$(echo /home/user)'/~}"
2275expected-stdout:
2276	/etc/tmp
2277	/etc/tmp
2278	/home/user/tmp
2279---
2280name: eglob-substrpl-3c
2281description:
2282	Even more weird cases
2283stdin:
2284	HOME=/etc
2285	pfx=/home/user
2286	wd='$pfx/tmp'
2287	echo 1: ${wd/#$pfx/~}
2288	echo 2: ${wd/#\$pfx/~}
2289	echo 3: ${wd/#"$pfx"/~}
2290	echo 4: ${wd/#'$pfx'/~}
2291	echo 5: ${wd/#"\$pfx"/~}
2292	echo 6: ${wd/#'\$pfx'/~}
2293	ts='a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)'
2294	tp=a/b
2295	tr=c/d
2296	[[ -n $BASH_VERSION ]] && shopt -s extglob
2297	echo 7: ${ts/a\/b/$tr}
2298	echo 8: ${ts/a\/b/\$tr}
2299	echo 9: ${ts/$tp/$tr}
2300	echo 10: ${ts/\$tp/$tr}
2301	echo 11: ${ts/\\$tp/$tr}
2302	echo 12: ${ts/$tp/c/d}
2303	echo 13: ${ts/$tp/c\/d}
2304	echo 14: ${ts/$tp/c\\/d}
2305	echo 15: ${ts/+(a\/b)/$tr}
2306	echo 16: ${ts/+(a\/b)/\$tr}
2307	echo 17: ${ts/+($tp)/$tr}
2308	echo 18: ${ts/+($tp)/c/d}
2309	echo 19: ${ts/+($tp)/c\/d}
2310	echo 20: ${ts//a\/b/$tr}
2311	echo 21: ${ts//a\/b/\$tr}
2312	echo 22: ${ts//$tp/$tr}
2313	echo 23: ${ts//$tp/c/d}
2314	echo 24: ${ts//$tp/c\/d}
2315	echo 25: ${ts//+(a\/b)/$tr}
2316	echo 26: ${ts//+(a\/b)/\$tr}
2317	echo 27: ${ts//+($tp)/$tr}
2318	echo 28: ${ts//+($tp)/c/d}
2319	echo 29: ${ts//+($tp)/c\/d}
2320	tp="+($tp)"
2321	echo 30: ${ts/$tp/$tr}
2322	echo 31: ${ts//$tp/$tr}
2323expected-stdout:
2324	1: $pfx/tmp
2325	2: /etc/tmp
2326	3: $pfx/tmp
2327	4: /etc/tmp
2328	5: /etc/tmp
2329	6: $pfx/tmp
2330	7: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2331	8: $tra/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2332	9: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2333	10: a/ba/bc/d$tp_a/b$tp_*(a/b)_*($tp)
2334	11: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2335	12: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2336	13: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2337	14: c\/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2338	15: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2339	16: $tr$tp$tp_a/b$tp_*(a/b)_*($tp)
2340	17: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2341	18: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2342	19: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2343	20: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2344	21: $tr$tr$tp$tp_$tr$tp_*($tr)_*($tp)
2345	22: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2346	23: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2347	24: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2348	25: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2349	26: $tr$tp$tp_$tr$tp_*($tr)_*($tp)
2350	27: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2351	28: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2352	29: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2353	30: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2354	31: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2355#	This is what GNU bash does:
2356#	30: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2357#	31: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2358---
2359name: eglob-utf8-1
2360description:
2361	UTF-8 mode differences for eglobbing
2362category: !shell:ebcdic-yes
2363stdin:
2364	s=blöd
2365	set +U
2366	print 1: ${s%???} .
2367	print 2: ${s/b???d/x} .
2368	set -U
2369	print 3: ${s%???} .
2370	print 4: ${s/b??d/x} .
2371	x=nö
2372	print 5: ${x%?} ${x%%?} .
2373	x=äh
2374	print 6: ${x#?} ${x##?} .
2375	x=��
2376	print 7: ${x%?} ${x%%?} .
2377	x=mä�
2378	print 8: ${x%?} ${x%%?} .
2379	x=何
2380	print 9: ${x%?} ${x%%?} .
2381expected-stdout:
2382	1: bl .
2383	2: x .
2384	3: b .
2385	4: x .
2386	5: n n .
2387	6: h h .
2388	7: � � .
2389	8: mä mä .
2390	9: .
2391---
2392name: glob-bad-1
2393description:
2394	Check that [ matches itself if it's not a valid bracket expr
2395	but does not prevent globbing, while backslash-escaping does
2396file-setup: dir 755 "[x"
2397file-setup: file 644 "[x/foo"
2398stdin:
2399	echo [*
2400	echo *[x
2401	echo [x/*
2402	:>'ab[x'
2403	:>'a[a-z][x'
2404	echo a[a-z][*
2405	echo a[a-z]*
2406	echo a[a\-z]*
2407expected-stdout:
2408	[x
2409	[x
2410	[x/foo
2411	ab[x
2412	ab[x
2413	a[a-z]*
2414---
2415name: glob-bad-2
2416description:
2417	Check that symbolic links aren't stat()'d
2418# breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails
2419# breaks on FreeMiNT (cannot unlink dangling symlinks)
2420# breaks on MSYS, OS/2 (do not support symlinks)
2421category: !os:mint,!os:msys,!os:svr4.0,!nosymlink
2422file-setup: dir 755 "dir"
2423file-setup: symlink 644 "dir/abc"
2424	non-existent-file
2425stdin:
2426	echo d*/*
2427	echo d*/abc
2428expected-stdout:
2429	dir/abc
2430	dir/abc
2431---
2432name: glob-bad-3
2433description:
2434	Check that the slash is parsed before the glob
2435stdin:
2436	mkdir a 'a[b'
2437	(cd 'a[b'; echo ok >'c]d')
2438	echo nok >abd
2439	echo fail >a/d
2440	cat a[b/c]d
2441expected-stdout:
2442	ok
2443---
2444name: glob-range-1
2445description:
2446	Test range matching
2447file-setup: file 644 ".bc"
2448file-setup: file 644 "abc"
2449file-setup: file 644 "bbc"
2450file-setup: file 644 "cbc"
2451file-setup: file 644 "-bc"
2452file-setup: file 644 "!bc"
2453file-setup: file 644 "^bc"
2454file-setup: file 644 "+bc"
2455file-setup: file 644 ",bc"
2456file-setup: file 644 "0bc"
2457file-setup: file 644 "1bc"
2458stdin:
2459	echo [ab-]*
2460	echo [-ab]*
2461	echo [!-ab]*
2462	echo [!ab]*
2463	echo []ab]*
2464	echo [^ab]*
2465	echo [+--]*
2466	echo [--1]*
2467
2468expected-stdout:
2469	-bc abc bbc
2470	-bc abc bbc
2471	!bc +bc ,bc 0bc 1bc ^bc cbc
2472	!bc +bc ,bc -bc 0bc 1bc ^bc cbc
2473	abc bbc
2474	^bc abc bbc
2475	+bc ,bc -bc
2476	-bc 0bc 1bc
2477---
2478name: glob-range-2
2479description:
2480	Test range matching
2481	(AT&T ksh fails this; POSIX says invalid)
2482file-setup: file 644 "abc"
2483stdin:
2484	echo [a--]*
2485expected-stdout:
2486	[a--]*
2487---
2488name: glob-range-3
2489description:
2490	Check that globbing matches the right things...
2491# breaks on Mac OSX (HFS+ non-standard UTF-8 canonical decomposition)
2492# breaks on Cygwin 1.7 (files are now UTF-16 or something)
2493# breaks on QNX 6.4.1 (says RT)
2494category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2,!os:os390
2495need-pass: no
2496file-setup: file 644 "a�c"
2497stdin:
2498	echo a[�-�]*
2499expected-stdout:
2500	a�c
2501---
2502name: glob-range-4
2503description:
2504	Results unspecified according to POSIX
2505file-setup: file 644 ".bc"
2506stdin:
2507	echo [a.]*
2508expected-stdout:
2509	[a.]*
2510---
2511name: glob-range-5
2512description:
2513	Results unspecified according to POSIX
2514	(AT&T ksh treats this like [a-cc-e]*)
2515file-setup: file 644 "abc"
2516file-setup: file 644 "bbc"
2517file-setup: file 644 "cbc"
2518file-setup: file 644 "dbc"
2519file-setup: file 644 "ebc"
2520file-setup: file 644 "-bc"
2521file-setup: file 644 "@bc"
2522stdin:
2523	echo [a-c-e]*
2524	echo [a--@]*
2525expected-stdout:
2526	-bc abc bbc cbc ebc
2527	@bc
2528---
2529name: glob-word-1
2530description:
2531	Check BSD word boundary matches
2532stdin:
2533	t() { [[ $1 = *[[:\<:]]bar[[:\>:]]* ]]; echo =$?; }
2534	t 'foo bar baz'
2535	t 'foobar baz'
2536	t 'foo barbaz'
2537	t 'bar'
2538	t '_bar'
2539	t 'bar_'
2540expected-stdout:
2541	=0
2542	=1
2543	=1
2544	=0
2545	=1
2546	=1
2547---
2548name: glob-trim-1
2549description:
2550	Check against a regression from fixing IFS-subst-2
2551stdin:
2552	x='#foo'
2553	print -r "before='$x'"
2554	x=${x%%#*}
2555	print -r "after ='$x'"
2556expected-stdout:
2557	before='#foo'
2558	after =''
2559---
2560name: heredoc-1
2561description:
2562	Check ordering/content of redundent here documents.
2563stdin:
2564	cat << EOF1 << EOF2
2565	hi
2566	EOF1
2567	there
2568	EOF2
2569expected-stdout:
2570	there
2571---
2572name: heredoc-2
2573description:
2574	Check quoted here-doc is protected.
2575stdin:
2576	a=foo
2577	cat << 'EOF'
2578	hi\
2579	there$a
2580	stuff
2581	EO\
2582	F
2583	EOF
2584expected-stdout:
2585	hi\
2586	there$a
2587	stuff
2588	EO\
2589	F
2590---
2591name: heredoc-3
2592description:
2593	Check that newline isn't needed after heredoc-delimiter marker.
2594stdin: !
2595	cat << EOF
2596	hi
2597	there
2598	EOF
2599expected-stdout:
2600	hi
2601	there
2602---
2603name: heredoc-4a
2604description:
2605	Check that an error occurs if the heredoc-delimiter is missing.
2606stdin: !
2607	cat << EOF
2608	hi
2609	there
2610expected-exit: e > 0
2611expected-stderr-pattern: /.*/
2612---
2613name: heredoc-4an
2614description:
2615	Check that an error occurs if the heredoc-delimiter is missing.
2616arguments: !-n!
2617stdin: !
2618	cat << EOF
2619	hi
2620	there
2621expected-exit: e > 0
2622expected-stderr-pattern: /.*/
2623---
2624name: heredoc-4b
2625description:
2626	Check that an error occurs if the heredoc is missing.
2627stdin: !
2628	cat << EOF
2629expected-exit: e > 0
2630expected-stderr-pattern: /.*/
2631---
2632name: heredoc-4bn
2633description:
2634	Check that an error occurs if the heredoc is missing.
2635arguments: !-n!
2636stdin: !
2637	cat << EOF
2638expected-exit: e > 0
2639expected-stderr-pattern: /.*/
2640---
2641name: heredoc-5
2642description:
2643	Check that backslash quotes a $, ` and \ and kills a \newline
2644stdin:
2645	a=BAD
2646	b=ok
2647	cat << EOF
2648	h\${a}i
2649	h\\${b}i
2650	th\`echo not-run\`ere
2651	th\\`echo is-run`ere
2652	fol\\ks
2653	more\\
2654	last \
2655	line
2656	EOF
2657expected-stdout:
2658	h${a}i
2659	h\oki
2660	th`echo not-run`ere
2661	th\is-runere
2662	fol\ks
2663	more\
2664	last line
2665---
2666name: heredoc-6
2667description:
2668	Check that \newline in initial here-delim word doesn't imply
2669	a quoted here-doc.
2670stdin:
2671	a=i
2672	cat << EO\
2673	F
2674	h$a
2675	there
2676	EOF
2677expected-stdout:
2678	hi
2679	there
2680---
2681name: heredoc-7
2682description:
2683	Check that double quoted $ expressions in here delimiters are
2684	not expanded and match the delimiter.
2685	POSIX says only quote removal is applied to the delimiter.
2686stdin:
2687	a=b
2688	cat << "E$a"
2689	hi
2690	h$a
2691	hb
2692	E$a
2693	echo done
2694expected-stdout:
2695	hi
2696	h$a
2697	hb
2698	done
2699---
2700name: heredoc-8
2701description:
2702	Check that double quoted escaped $ expressions in here
2703	delimiters are not expanded and match the delimiter.
2704	POSIX says only quote removal is applied to the delimiter
2705	(\ counts as a quote).
2706stdin:
2707	a=b
2708	cat << "E\$a"
2709	hi
2710	h$a
2711	h\$a
2712	hb
2713	h\b
2714	E$a
2715	echo done
2716expected-stdout:
2717	hi
2718	h$a
2719	h\$a
2720	hb
2721	h\b
2722	done
2723---
2724name: heredoc-9a
2725description:
2726	Check that here strings work.
2727stdin:
2728	bar="bar
2729		baz"
2730	tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo
2731	"$__progname" -c "tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo"
2732	tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$bar"
2733	tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<'$bar'
2734	tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar
2735	tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo
2736	tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")"
2737	tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"A $(echo "foo bar") B"
2738	tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$b\$b$bar
2739expected-stdout:
2740	sbb
2741	sbb
2742	one
2743		onm
2744	$one
2745	$one
2746	-sbb
2747	sbb one
2748	A sbb one B
2749	$o$oone
2750		onm
2751---
2752name: heredoc-9b
2753description:
2754	Check that a corner case of here strings works like bash
2755stdin:
2756	fnord=42
2757	bar="bar
2758		 \$fnord baz"
2759	tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2760expected-stdout:
2761	one $sabeq onm
2762category: bash
2763---
2764name: heredoc-9c
2765description:
2766	Check that a corner case of here strings works like ksh93, zsh
2767stdin:
2768	fnord=42
2769	bar="bar
2770		 \$fnord baz"
2771	tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2772expected-stdout:
2773	one
2774		 $sabeq onm
2775---
2776name: heredoc-9d
2777description:
2778	Check another corner case of here strings
2779stdin:
2780	tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar
2781expected-stdout:
2782	one
2783---
2784name: heredoc-9e
2785description:
2786	Check here string related regression with multiple iops
2787stdin:
2788	echo $(tr r z <<<'bar' 2>/dev/null)
2789expected-stdout:
2790	baz
2791---
2792name: heredoc-9f
2793description:
2794	Check long here strings
2795stdin:
2796	cat <<< "$(  :                                                             )aa"
2797expected-stdout:
2798	aa
2799---
2800name: heredoc-10
2801description:
2802	Check direct here document assignment
2803category: !shell:ebcdic-yes
2804stdin:
2805	x=u
2806	va=<<EOF
2807	=a $x \x40=
2808	EOF
2809	vb=<<'EOF'
2810	=b $x \x40=
2811	EOF
2812	function foo {
2813		vc=<<-EOF
2814			=c $x \x40=
2815		EOF
2816	}
2817	fnd=$(typeset -f foo)
2818	print -r -- "$fnd"
2819	function foo {
2820		echo blub
2821	}
2822	foo
2823	eval "$fnd"
2824	foo
2825	# rather nonsensical, but…
2826	vd=<<<"=d $x \x40="
2827	ve=<<<'=e $x \x40='
2828	vf=<<<$'=f $x \x40='
2829	# now check
2830	print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
2831	# check append
2832	v=<<-EOF
2833		vapp1
2834	EOF
2835	v+=<<-EOF
2836		vapp2
2837	EOF
2838	print -r -- "| ${v//$'\n'/^} |"
2839expected-stdout:
2840	function foo {
2841		vc=<<-EOF
2842	=c $x \x40=
2843	EOF
2844
2845	}
2846	blub
2847	| va={=a u \x40=
2848	} vb={=b $x \x40=
2849	} vc={=c u \x40=
2850	} vd={=d u \x40=
2851	} ve={=e $x \x40=
2852	} vf={=f $x @=
2853	} |
2854	| vapp1^vapp2^ |
2855---
2856name: heredoc-10-ebcdic
2857description:
2858	Check direct here document assignment
2859category: !shell:ebcdic-no
2860stdin:
2861	x=u
2862	va=<<EOF
2863	=a $x \x7C=
2864	EOF
2865	vb=<<'EOF'
2866	=b $x \x7C=
2867	EOF
2868	function foo {
2869		vc=<<-EOF
2870			=c $x \x7C=
2871		EOF
2872	}
2873	fnd=$(typeset -f foo)
2874	print -r -- "$fnd"
2875	function foo {
2876		echo blub
2877	}
2878	foo
2879	eval "$fnd"
2880	foo
2881	# rather nonsensical, but…
2882	vd=<<<"=d $x \x7C="
2883	ve=<<<'=e $x \x7C='
2884	vf=<<<$'=f $x \x7C='
2885	# now check
2886	print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
2887	# check append
2888	v=<<-EOF
2889		vapp1
2890	EOF
2891	v+=<<-EOF
2892		vapp2
2893	EOF
2894	print -r -- "| ${v//$'\n'/^} |"
2895expected-stdout:
2896	function foo {
2897		vc=<<-EOF
2898	=c $x \x7C=
2899	EOF
2900
2901	}
2902	blub
2903	| va={=a u \x7C=
2904	} vb={=b $x \x7C=
2905	} vc={=c u \x7C=
2906	} vd={=d u \x7C=
2907	} ve={=e $x \x7C=
2908	} vf={=f $x @=
2909	} |
2910	| vapp1^vapp2^ |
2911---
2912name: heredoc-11
2913description:
2914	Check here documents with no or empty delimiter
2915stdin:
2916	x=u
2917	va=<<
2918	=a $x \x40=
2919	<<
2920	vb=<<''
2921	=b $x \x40=
2922
2923	function foo {
2924		vc=<<-
2925			=c $x \x40=
2926		<<
2927		vd=<<-''
2928			=d $x \x40=
2929
2930	}
2931	fnd=$(typeset -f foo)
2932	print -r -- "$fnd"
2933	function foo {
2934		echo blub
2935	}
2936	foo
2937	eval "$fnd"
2938	foo
2939	print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} |"
2940	x=y
2941	foo
2942	typeset -f foo
2943	print -r -- "| vc={$vc} vd={$vd} |"
2944	# check append
2945	v=<<-
2946		vapp1
2947	<<
2948	v+=<<-''
2949		vapp2
2950
2951	print -r -- "| ${v//$'\n'/^} |"
2952expected-stdout:
2953	function foo {
2954		vc=<<-
2955	=c $x \x40=
2956	<<
2957
2958		vd=<<-""
2959	=d $x \x40=
2960
2961
2962	}
2963	blub
2964	| va={=a u \x40=
2965	} vb={=b $x \x40=
2966	} vc={=c u \x40=
2967	} vd={=d $x \x40=
2968	} |
2969	function foo {
2970		vc=<<-
2971	=c $x \x40=
2972	<<
2973
2974		vd=<<-""
2975	=d $x \x40=
2976
2977
2978	}
2979	| vc={=c y \x40=
2980	} vd={=d $x \x40=
2981	} |
2982	| vapp1^vapp2^ |
2983---
2984name: heredoc-12
2985description:
2986	Check here documents can use $* and $@; note shells vary:
2987	• pdksh 5.2.14 acts the same
2988	• dash has 1 and 2 the same but 3 lacks the space
2989	• ksh93, bash4 differ in 2 by using space ipv colon
2990stdin:
2991	set -- a b
2992	nl='
2993	'
2994	IFS=" 	$nl"; n=1
2995	cat <<EOF
2996	$n foo $* foo
2997	$n bar "$*" bar
2998	$n baz $@ baz
2999	$n bla "$@" bla
3000	EOF
3001	IFS=":"; n=2
3002	cat <<EOF
3003	$n foo $* foo
3004	$n bar "$*" bar
3005	$n baz $@ baz
3006	$n bla "$@" bla
3007	EOF
3008	IFS=; n=3
3009	cat <<EOF
3010	$n foo $* foo
3011	$n bar "$*" bar
3012	$n baz $@ baz
3013	$n bla "$@" bla
3014	EOF
3015expected-stdout:
3016	1 foo a b foo
3017	1 bar "a b" bar
3018	1 baz a b baz
3019	1 bla "a b" bla
3020	2 foo a:b foo
3021	2 bar "a:b" bar
3022	2 baz a:b baz
3023	2 bla "a:b" bla
3024	3 foo a b foo
3025	3 bar "a b" bar
3026	3 baz a b baz
3027	3 bla "a b" bla
3028---
3029name: heredoc-14
3030description:
3031	Check that using multiple here documents works
3032stdin:
3033	foo() {
3034		echo "got $(cat) on stdin"
3035		echo "got $(cat <&4) on fd#4"
3036		echo "got $(cat <&5) on fd#5"
3037	}
3038	bar() {
3039		foo 4<<-a <<-b 5<<-c
3040		four
3041		a
3042		zero
3043		b
3044		five
3045		c
3046	}
3047	x=$(typeset -f bar)
3048	eval "$x"
3049	y=$(typeset -f bar)
3050	[[ $x = "$y" ]]; echo $?
3051	typeset -f bar
3052	bar
3053expected-stdout:
3054	0
3055	bar() {
3056		\foo 4<<-a <<-b 5<<-c
3057	four
3058	a
3059	zero
3060	b
3061	five
3062	c
3063
3064	}
3065	got zero on stdin
3066	got four on fd#4
3067	got five on fd#5
3068---
3069name: heredoc-15
3070description:
3071	Check high-bit7 separators work
3072stdin:
3073	u=ä
3074	tr a-z A-Z <<-…
3075		m${u}h
30763077	echo ok
3078expected-stdout:
3079	MäH
3080	ok
3081---
3082name: heredoc-comsub-1
3083description:
3084	Tests for here documents in COMSUB, taken from Austin ML
3085stdin:
3086	text=$(cat <<EOF
3087	here is the text
3088	EOF)
3089	echo = $text =
3090expected-stdout:
3091	= here is the text =
3092---
3093name: heredoc-comsub-2
3094description:
3095	Tests for here documents in COMSUB, taken from Austin ML
3096stdin:
3097	unbalanced=$(cat <<EOF
3098	this paren ) is a problem
3099	EOF)
3100	echo = $unbalanced =
3101expected-stdout:
3102	= this paren ) is a problem =
3103---
3104name: heredoc-comsub-3
3105description:
3106	Tests for here documents in COMSUB, taken from Austin ML
3107stdin:
3108	balanced=$(cat <<EOF
3109	these parens ( ) are not a problem
3110	EOF)
3111	echo = $balanced =
3112expected-stdout:
3113	= these parens ( ) are not a problem =
3114---
3115name: heredoc-comsub-4
3116description:
3117	Tests for here documents in COMSUB, taken from Austin ML
3118stdin:
3119	balanced=$(cat <<EOF
3120	these parens \( ) are a problem
3121	EOF)
3122	echo = $balanced =
3123expected-stdout:
3124	= these parens \( ) are a problem =
3125---
3126name: heredoc-comsub-5
3127description:
3128	Check heredoc and COMSUB mixture in input
3129stdin:
3130	prefix() { sed -e "s/^/$1:/"; }
3131	XXX() { echo x-en; }
3132	YYY() { echo y-es; }
3133
3134	prefix A <<XXX && echo "$(prefix B <<XXX
3135	echo line 1
3136	XXX
3137	echo line 2)" && prefix C <<YYY
3138	echo line 3
3139	XXX
3140	echo line 4)"
3141	echo line 5
3142	YYY
3143	XXX
3144expected-stdout:
3145	A:echo line 3
3146	B:echo line 1
3147	line 2
3148	C:echo line 4)"
3149	C:echo line 5
3150	x-en
3151---
3152name: heredoc-comsub-6
3153description:
3154	Check here documents and here strings can be used
3155	without a specific command, like $(<…) (extension)
3156stdin:
3157	foo=bar
3158	x=$(<<<EO${foo}F)
3159	echo "3<$x>"
3160		y=$(<<-EOF
3161			hi!
3162
3163			$foo) is not a problem
3164
3165
3166		EOF)
3167	echo "7<$y>"
3168expected-stdout:
3169	3<EObarF>
3170	7<hi!
3171
3172	bar) is not a problem>
3173---
3174name: heredoc-subshell-1
3175description:
3176	Tests for here documents in subshells, taken from Austin ML
3177stdin:
3178	(cat <<EOF
3179	some text
3180	EOF)
3181	echo end
3182expected-stdout:
3183	some text
3184	end
3185---
3186name: heredoc-subshell-2
3187description:
3188	Tests for here documents in subshells, taken from Austin ML
3189stdin:
3190	(cat <<EOF
3191	some text
3192	EOF
3193	)
3194	echo end
3195expected-stdout:
3196	some text
3197	end
3198---
3199name: heredoc-subshell-3
3200description:
3201	Tests for here documents in subshells, taken from Austin ML
3202stdin:
3203	(cat <<EOF; )
3204	some text
3205	EOF
3206	echo end
3207expected-stdout:
3208	some text
3209	end
3210---
3211name: heredoc-weird-1
3212description:
3213	Tests for here documents, taken from Austin ML
3214	Documents current state in mksh, *NOT* necessarily correct!
3215stdin:
3216	cat <<END
3217	hello
3218	END\
3219	END
3220	END
3221	echo end
3222expected-stdout:
3223	hello
3224	ENDEND
3225	end
3226---
3227name: heredoc-weird-2
3228description:
3229	Tests for here documents, taken from Austin ML
3230stdin:
3231	cat <<'    END    '
3232	hello
3233	    END
3234	echo end
3235expected-stdout:
3236	hello
3237	end
3238---
3239name: heredoc-weird-4
3240description:
3241	Tests for here documents, taken from Austin ML
3242	Documents current state in mksh, *NOT* necessarily correct!
3243stdin:
3244	cat <<END
3245	hello\
3246	END
3247	END
3248	echo end
3249expected-stdout:
3250	helloEND
3251	end
3252---
3253name: heredoc-weird-5
3254description:
3255	Tests for here documents, taken from Austin ML
3256	Documents current state in mksh, *NOT* necessarily correct!
3257stdin:
3258	cat <<END
3259	hello
3260	\END
3261	END
3262	echo end
3263expected-stdout:
3264	hello
3265	\END
3266	end
3267---
3268name: heredoc-tmpfile-1
3269description:
3270	Check that heredoc temp files aren't removed too soon or too late.
3271	Heredoc in simple command.
3272stdin:
3273	TMPDIR=$PWD
3274	eval '
3275		cat <<- EOF
3276		hi
3277		EOF
3278		for i in a b ; do
3279			cat <<- EOF
3280			more
3281			EOF
3282		done
3283	    ' &
3284	sleep 1
3285	echo Left overs: *
3286expected-stdout:
3287	hi
3288	more
3289	more
3290	Left overs: *
3291---
3292name: heredoc-tmpfile-2
3293description:
3294	Check that heredoc temp files aren't removed too soon or too late.
3295	Heredoc in function, multiple calls to function.
3296stdin:
3297	TMPDIR=$PWD
3298	eval '
3299		foo() {
3300			cat <<- EOF
3301			hi
3302			EOF
3303		}
3304		foo
3305		foo
3306	    ' &
3307	sleep 1
3308	echo Left overs: *
3309expected-stdout:
3310	hi
3311	hi
3312	Left overs: *
3313---
3314name: heredoc-tmpfile-3
3315description:
3316	Check that heredoc temp files aren't removed too soon or too late.
3317	Heredoc in function in loop, multiple calls to function.
3318stdin:
3319	TMPDIR=$PWD
3320	eval '
3321		foo() {
3322			cat <<- EOF
3323			hi
3324			EOF
3325		}
3326		for i in a b; do
3327			foo
3328			foo() {
3329				cat <<- EOF
3330				folks $i
3331				EOF
3332			}
3333		done
3334		foo
3335	    ' &
3336	sleep 1
3337	echo Left overs: *
3338expected-stdout:
3339	hi
3340	folks b
3341	folks b
3342	Left overs: *
3343---
3344name: heredoc-tmpfile-4
3345description:
3346	Check that heredoc temp files aren't removed too soon or too late.
3347	Backgrounded simple command with here doc
3348stdin:
3349	TMPDIR=$PWD
3350	eval '
3351		cat <<- EOF &
3352		hi
3353		EOF
3354	    ' &
3355	sleep 1
3356	echo Left overs: *
3357expected-stdout:
3358	hi
3359	Left overs: *
3360---
3361name: heredoc-tmpfile-5
3362description:
3363	Check that heredoc temp files aren't removed too soon or too late.
3364	Backgrounded subshell command with here doc
3365stdin:
3366	TMPDIR=$PWD
3367	eval '
3368	      (
3369		sleep 1	# so parent exits
3370		echo A
3371		cat <<- EOF
3372		hi
3373		EOF
3374		echo B
3375	      ) &
3376	    ' &
3377	sleep 5
3378	echo Left overs: *
3379expected-stdout:
3380	A
3381	hi
3382	B
3383	Left overs: *
3384---
3385name: heredoc-tmpfile-6
3386description:
3387	Check that heredoc temp files aren't removed too soon or too late.
3388	Heredoc in pipeline.
3389stdin:
3390	TMPDIR=$PWD
3391	eval '
3392		cat <<- EOF | sed "s/hi/HI/"
3393		hi
3394		EOF
3395	    ' &
3396	sleep 1
3397	echo Left overs: *
3398expected-stdout:
3399	HI
3400	Left overs: *
3401---
3402name: heredoc-tmpfile-7
3403description:
3404	Check that heredoc temp files aren't removed too soon or too late.
3405	Heredoc in backgrounded pipeline.
3406stdin:
3407	TMPDIR=$PWD
3408	eval '
3409		cat <<- EOF | sed 's/hi/HI/' &
3410		hi
3411		EOF
3412	    ' &
3413	sleep 1
3414	echo Left overs: *
3415expected-stdout:
3416	HI
3417	Left overs: *
3418---
3419name: heredoc-tmpfile-8
3420description:
3421	Check that heredoc temp files aren't removed too soon or too
3422	late. Heredoc in function, backgrounded call to function.
3423	This check can fail on slow machines (<100 MHz), or Cygwin,
3424	that's normal.
3425need-pass: no
3426stdin:
3427	TMPDIR=$PWD
3428	# Background eval so main shell doesn't do parsing
3429	eval '
3430		foo() {
3431			cat <<- EOF
3432			hi
3433			EOF
3434		}
3435		foo
3436		# sleep so eval can die
3437		(sleep 1; foo) &
3438		(sleep 1; foo) &
3439		foo
3440	    ' &
3441	sleep 5
3442	echo Left overs: *
3443expected-stdout:
3444	hi
3445	hi
3446	hi
3447	hi
3448	Left overs: *
3449---
3450name: heredoc-quoting-unsubst
3451description:
3452	Check for correct handling of quoted characters in
3453	here documents without substitution (marker is quoted).
3454stdin:
3455	foo=bar
3456	cat <<-'EOF'
3457		x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3458	EOF
3459expected-stdout:
3460	x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3461---
3462name: heredoc-quoting-subst
3463description:
3464	Check for correct handling of quoted characters in
3465	here documents with substitution (marker is not quoted).
3466stdin:
3467	foo=bar
3468	cat <<-EOF
3469		x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3470	EOF
3471expected-stdout:
3472	x " \" \ \ $ $ baz `echo baz` bar $foo x
3473---
3474name: single-quotes-in-braces
3475description:
3476	Check that single quotes inside unquoted {} are treated as quotes
3477stdin:
3478	foo=1
3479	echo ${foo:+'blah  $foo'}
3480expected-stdout:
3481	blah  $foo
3482---
3483name: single-quotes-in-quoted-braces
3484description:
3485	Check that single quotes inside quoted {} are treated as
3486	normal char
3487stdin:
3488	foo=1
3489	echo "${foo:+'blah  $foo'}"
3490expected-stdout:
3491	'blah  1'
3492---
3493name: single-quotes-in-braces-nested
3494description:
3495	Check that single quotes inside unquoted {} are treated as quotes,
3496	even if that's inside a double-quoted command expansion
3497stdin:
3498	foo=1
3499	echo "$( echo ${foo:+'blah  $foo'})"
3500expected-stdout:
3501	blah  $foo
3502---
3503name: single-quotes-in-brace-pattern
3504description:
3505	Check that single quotes inside {} pattern are treated as quotes
3506stdin:
3507	foo=1234
3508	echo ${foo%'2'*} "${foo%'2'*}" ${foo%2'*'} "${foo%2'*'}"
3509expected-stdout:
3510	1 1 1234 1234
3511---
3512name: single-quotes-in-heredoc-braces
3513description:
3514	Check that single quotes inside {} in heredoc are treated
3515	as normal char
3516stdin:
3517	foo=1
3518	cat <<EOM
3519	${foo:+'blah  $foo'}
3520	EOM
3521expected-stdout:
3522	'blah  1'
3523---
3524name: single-quotes-in-nested-braces
3525description:
3526	Check that single quotes inside nested unquoted {} are
3527	treated as quotes
3528stdin:
3529	foo=1
3530	echo ${foo:+${foo:+'blah  $foo'}}
3531expected-stdout:
3532	blah  $foo
3533---
3534name: single-quotes-in-nested-quoted-braces
3535description:
3536	Check that single quotes inside nested quoted {} are treated
3537	as normal char
3538stdin:
3539	foo=1
3540	echo "${foo:+${foo:+'blah  $foo'}}"
3541expected-stdout:
3542	'blah  1'
3543---
3544name: single-quotes-in-nested-braces-nested
3545description:
3546	Check that single quotes inside nested unquoted {} are treated
3547	as quotes, even if that's inside a double-quoted command expansion
3548stdin:
3549	foo=1
3550	echo "$( echo ${foo:+${foo:+'blah  $foo'}})"
3551expected-stdout:
3552	blah  $foo
3553---
3554name: single-quotes-in-nested-brace-pattern
3555description:
3556	Check that single quotes inside nested {} pattern are treated as quotes
3557stdin:
3558	foo=1234
3559	echo ${foo:+${foo%'2'*}} "${foo:+${foo%'2'*}}" ${foo:+${foo%2'*'}} "${foo:+${foo%2'*'}}"
3560expected-stdout:
3561	1 1 1234 1234
3562---
3563name: single-quotes-in-heredoc-nested-braces
3564description:
3565	Check that single quotes inside nested {} in heredoc are treated
3566	as normal char
3567stdin:
3568	foo=1
3569	cat <<EOM
3570	${foo:+${foo:+'blah  $foo'}}
3571	EOM
3572expected-stdout:
3573	'blah  1'
3574---
3575name: single-quotes-in-heredoc-trim
3576description:
3577	In some cases, single quotes inside {} in heredoc are not normal
3578stdin:
3579	x=notOK
3580	cat <<EOF
3581	1: ${x#not} ${x:+${x#not}}
3582	2: ${x#\n\o\t} ${x:+${x#\n\o\t}}
3583	3: ${x#"not"} ${x:+${x#"not"}}
3584	4: ${x#'not'} ${x:+${x#'not'}}
3585	5: ${x#$'not'} ${x:+${x#$'not'}}
3586	EOF
3587expected-stdout:
3588	1: OK OK
3589	2: OK OK
3590	3: OK OK
3591	4: OK OK
3592	5: OK OK
3593---
3594name: history-basic
3595description:
3596	See if we can test history at all
3597need-ctty: yes
3598arguments: !-i!
3599env-setup: !ENV=./Env!HISTFILE=hist.file!
3600file-setup: file 644 "Env"
3601	PS1=X
3602stdin:
3603	echo hi
3604	fc -l
3605expected-stdout:
3606	hi
3607	1	echo hi
3608expected-stderr-pattern:
3609	/^X*$/
3610---
3611name: history-dups
3612description:
3613	Verify duplicates and spaces are not entered
3614need-ctty: yes
3615arguments: !-i!
3616env-setup: !ENV=./Env!HISTFILE=hist.file!
3617file-setup: file 644 "Env"
3618	PS1=X
3619stdin:
3620	echo hi
3621	 echo yo
3622	echo hi
3623	fc -l
3624expected-stdout:
3625	hi
3626	yo
3627	hi
3628	1	echo hi
3629expected-stderr-pattern:
3630	/^X*$/
3631---
3632name: history-unlink
3633description:
3634	Check if broken HISTFILEs do not cause trouble
3635need-ctty: yes
3636arguments: !-i!
3637env-setup: !ENV=./Env!HISTFILE=foo/hist.file!
3638file-setup: file 644 "Env"
3639	PS1=X
3640file-setup: dir 755 "foo"
3641file-setup: file 644 "foo/hist.file"
3642	sometext
3643time-limit: 5
3644perl-setup: chmod(0555, "foo");
3645stdin:
3646	echo hi
3647	fc -l
3648	chmod 0755 foo
3649expected-stdout:
3650	hi
3651	1	echo hi
3652expected-stderr-pattern:
3653	/(.*can't unlink HISTFILE.*\n)?X*$/
3654---
3655name: history-multiline
3656description:
3657	Check correct multiline history, Debian #783978
3658need-ctty: yes
3659arguments: !-i!
3660env-setup: !ENV=./Env!
3661file-setup: file 644 "Env"
3662	PS1=X
3663	PS2=Y
3664stdin:
3665	for i in A B C
3666	do
3667	   print $i
3668	   print $i
3669	done
3670	fc -l
3671expected-stdout:
3672	A
3673	A
3674	B
3675	B
3676	C
3677	C
3678	1	for i in A B C
3679		do
3680		   print $i
3681		   print $i
3682		done
3683expected-stderr-pattern:
3684	/^XYYYYXX$/
3685---
3686name: history-e-minus-1
3687description:
3688	Check if more recent command is executed
3689need-ctty: yes
3690arguments: !-i!
3691env-setup: !ENV=./Env!HISTFILE=hist.file!
3692file-setup: file 644 "Env"
3693	PS1=X
3694stdin:
3695	echo hi
3696	echo there
3697	fc -e -
3698expected-stdout:
3699	hi
3700	there
3701	there
3702expected-stderr-pattern:
3703	/^X*echo there\nX*$/
3704---
3705name: history-e-minus-2
3706description:
3707	Check that repeated command is printed before command
3708	is re-executed.
3709need-ctty: yes
3710arguments: !-i!
3711env-setup: !ENV=./Env!HISTFILE=hist.file!
3712file-setup: file 644 "Env"
3713	PS1=X
3714stdin:
3715	exec 2>&1
3716	echo hi
3717	echo there
3718	fc -e -
3719expected-stdout-pattern:
3720	/X*hi\nX*there\nX*echo there\nthere\nX*/
3721expected-stderr-pattern:
3722	/^X*$/
3723---
3724name: history-e-minus-3
3725description:
3726	fc -e - fails when there is no history
3727	(ksh93 has a bug that causes this to fail)
3728	(ksh88 loops on this)
3729need-ctty: yes
3730arguments: !-i!
3731env-setup: !ENV=./Env!HISTFILE=hist.file!
3732file-setup: file 644 "Env"
3733	PS1=X
3734stdin:
3735	fc -e -
3736	echo ok
3737expected-stdout:
3738	ok
3739expected-stderr-pattern:
3740	/^X*.*:.*history.*\nX*$/
3741---
3742name: history-e-minus-4
3743description:
3744	Check if "fc -e -" command output goes to stdout.
3745need-ctty: yes
3746arguments: !-i!
3747env-setup: !ENV=./Env!HISTFILE=hist.file!
3748file-setup: file 644 "Env"
3749	PS1=X
3750stdin:
3751	echo abc
3752	fc -e - | (read x; echo "A $x")
3753	echo ok
3754expected-stdout:
3755	abc
3756	A abc
3757	ok
3758expected-stderr-pattern:
3759	/^X*echo abc\nX*/
3760---
3761name: history-e-minus-5
3762description:
3763	fc is replaced in history by new command.
3764need-ctty: yes
3765arguments: !-i!
3766env-setup: !ENV=./Env!HISTFILE=hist.file!
3767file-setup: file 644 "Env"
3768	PS1=X
3769stdin:
3770	echo abc def
3771	echo ghi jkl
3772	:
3773	fc -e - echo
3774	fc -l 2 5
3775expected-stdout:
3776	abc def
3777	ghi jkl
3778	ghi jkl
3779	2	echo ghi jkl
3780	3	:
3781	4	echo ghi jkl
3782	5	fc -l 2 5
3783expected-stderr-pattern:
3784	/^X*echo ghi jkl\nX*$/
3785---
3786name: history-list-1
3787description:
3788	List lists correct range
3789	(ksh88 fails 'cause it lists the fc command)
3790need-ctty: yes
3791arguments: !-i!
3792env-setup: !ENV=./Env!HISTFILE=hist.file!
3793file-setup: file 644 "Env"
3794	PS1=X
3795stdin:
3796	echo line 1
3797	echo line 2
3798	echo line 3
3799	fc -l -- -2
3800expected-stdout:
3801	line 1
3802	line 2
3803	line 3
3804	2	echo line 2
3805	3	echo line 3
3806expected-stderr-pattern:
3807	/^X*$/
3808---
3809name: history-list-2
3810description:
3811	Lists oldest history if given pre-historic number
3812	(ksh93 has a bug that causes this to fail)
3813	(ksh88 fails 'cause it lists the fc command)
3814need-ctty: yes
3815arguments: !-i!
3816env-setup: !ENV=./Env!HISTFILE=hist.file!
3817file-setup: file 644 "Env"
3818	PS1=X
3819stdin:
3820	echo line 1
3821	echo line 2
3822	echo line 3
3823	fc -l -- -40
3824expected-stdout:
3825	line 1
3826	line 2
3827	line 3
3828	1	echo line 1
3829	2	echo line 2
3830	3	echo line 3
3831expected-stderr-pattern:
3832	/^X*$/
3833---
3834name: history-list-3
3835description:
3836	Can give number 'options' to fc
3837need-ctty: yes
3838arguments: !-i!
3839env-setup: !ENV=./Env!HISTFILE=hist.file!
3840file-setup: file 644 "Env"
3841	PS1=X
3842stdin:
3843	echo line 1
3844	echo line 2
3845	echo line 3
3846	echo line 4
3847	fc -l -3 -2
3848expected-stdout:
3849	line 1
3850	line 2
3851	line 3
3852	line 4
3853	2	echo line 2
3854	3	echo line 3
3855expected-stderr-pattern:
3856	/^X*$/
3857---
3858name: history-list-4
3859description:
3860	-1 refers to previous command
3861need-ctty: yes
3862arguments: !-i!
3863env-setup: !ENV=./Env!HISTFILE=hist.file!
3864file-setup: file 644 "Env"
3865	PS1=X
3866stdin:
3867	echo line 1
3868	echo line 2
3869	echo line 3
3870	echo line 4
3871	fc -l -1 -1
3872expected-stdout:
3873	line 1
3874	line 2
3875	line 3
3876	line 4
3877	4	echo line 4
3878expected-stderr-pattern:
3879	/^X*$/
3880---
3881name: history-list-5
3882description:
3883	List command stays in history
3884need-ctty: yes
3885arguments: !-i!
3886env-setup: !ENV=./Env!HISTFILE=hist.file!
3887file-setup: file 644 "Env"
3888	PS1=X
3889stdin:
3890	echo line 1
3891	echo line 2
3892	echo line 3
3893	echo line 4
3894	fc -l -1 -1
3895	fc -l -2 -1
3896expected-stdout:
3897	line 1
3898	line 2
3899	line 3
3900	line 4
3901	4	echo line 4
3902	4	echo line 4
3903	5	fc -l -1 -1
3904expected-stderr-pattern:
3905	/^X*$/
3906---
3907name: history-list-6
3908description:
3909	HISTSIZE limits about of history kept.
3910	(ksh88 fails 'cause it lists the fc command)
3911need-ctty: yes
3912arguments: !-i!
3913env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3914file-setup: file 644 "Env"
3915	PS1=X
3916stdin:
3917	echo line 1
3918	echo line 2
3919	echo line 3
3920	echo line 4
3921	echo line 5
3922	fc -l
3923expected-stdout:
3924	line 1
3925	line 2
3926	line 3
3927	line 4
3928	line 5
3929	4	echo line 4
3930	5	echo line 5
3931expected-stderr-pattern:
3932	/^X*$/
3933---
3934name: history-list-7
3935description:
3936	fc allows too old/new errors in range specification
3937need-ctty: yes
3938arguments: !-i!
3939env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3940file-setup: file 644 "Env"
3941	PS1=X
3942stdin:
3943	echo line 1
3944	echo line 2
3945	echo line 3
3946	echo line 4
3947	echo line 5
3948	fc -l 1 30
3949expected-stdout:
3950	line 1
3951	line 2
3952	line 3
3953	line 4
3954	line 5
3955	4	echo line 4
3956	5	echo line 5
3957	6	fc -l 1 30
3958expected-stderr-pattern:
3959	/^X*$/
3960---
3961name: history-list-r-1
3962description:
3963	test -r flag in history
3964need-ctty: yes
3965arguments: !-i!
3966env-setup: !ENV=./Env!HISTFILE=hist.file!
3967file-setup: file 644 "Env"
3968	PS1=X
3969stdin:
3970	echo line 1
3971	echo line 2
3972	echo line 3
3973	echo line 4
3974	echo line 5
3975	fc -l -r 2 4
3976expected-stdout:
3977	line 1
3978	line 2
3979	line 3
3980	line 4
3981	line 5
3982	4	echo line 4
3983	3	echo line 3
3984	2	echo line 2
3985expected-stderr-pattern:
3986	/^X*$/
3987---
3988name: history-list-r-2
3989description:
3990	If first is newer than last, -r is implied.
3991need-ctty: yes
3992arguments: !-i!
3993env-setup: !ENV=./Env!HISTFILE=hist.file!
3994file-setup: file 644 "Env"
3995	PS1=X
3996stdin:
3997	echo line 1
3998	echo line 2
3999	echo line 3
4000	echo line 4
4001	echo line 5
4002	fc -l 4 2
4003expected-stdout:
4004	line 1
4005	line 2
4006	line 3
4007	line 4
4008	line 5
4009	4	echo line 4
4010	3	echo line 3
4011	2	echo line 2
4012expected-stderr-pattern:
4013	/^X*$/
4014---
4015name: history-list-r-3
4016description:
4017	If first is newer than last, -r is cancelled.
4018need-ctty: yes
4019arguments: !-i!
4020env-setup: !ENV=./Env!HISTFILE=hist.file!
4021file-setup: file 644 "Env"
4022	PS1=X
4023stdin:
4024	echo line 1
4025	echo line 2
4026	echo line 3
4027	echo line 4
4028	echo line 5
4029	fc -l -r 4 2
4030expected-stdout:
4031	line 1
4032	line 2
4033	line 3
4034	line 4
4035	line 5
4036	2	echo line 2
4037	3	echo line 3
4038	4	echo line 4
4039expected-stderr-pattern:
4040	/^X*$/
4041---
4042name: history-subst-1
4043description:
4044	Basic substitution
4045need-ctty: yes
4046arguments: !-i!
4047env-setup: !ENV=./Env!HISTFILE=hist.file!
4048file-setup: file 644 "Env"
4049	PS1=X
4050stdin:
4051	echo abc def
4052	echo ghi jkl
4053	fc -e - abc=AB 'echo a'
4054expected-stdout:
4055	abc def
4056	ghi jkl
4057	AB def
4058expected-stderr-pattern:
4059	/^X*echo AB def\nX*$/
4060---
4061name: history-subst-2
4062description:
4063	Does subst find previous command?
4064need-ctty: yes
4065arguments: !-i!
4066env-setup: !ENV=./Env!HISTFILE=hist.file!
4067file-setup: file 644 "Env"
4068	PS1=X
4069stdin:
4070	echo abc def
4071	echo ghi jkl
4072	fc -e - jkl=XYZQRT 'echo g'
4073expected-stdout:
4074	abc def
4075	ghi jkl
4076	ghi XYZQRT
4077expected-stderr-pattern:
4078	/^X*echo ghi XYZQRT\nX*$/
4079---
4080name: history-subst-3
4081description:
4082	Does subst find previous command when no arguments given
4083need-ctty: yes
4084arguments: !-i!
4085env-setup: !ENV=./Env!HISTFILE=hist.file!
4086file-setup: file 644 "Env"
4087	PS1=X
4088stdin:
4089	echo abc def
4090	echo ghi jkl
4091	fc -e - jkl=XYZQRT
4092expected-stdout:
4093	abc def
4094	ghi jkl
4095	ghi XYZQRT
4096expected-stderr-pattern:
4097	/^X*echo ghi XYZQRT\nX*$/
4098---
4099name: history-subst-4
4100description:
4101	Global substitutions work
4102	(ksh88 and ksh93 do not have -g option)
4103need-ctty: yes
4104arguments: !-i!
4105env-setup: !ENV=./Env!HISTFILE=hist.file!
4106file-setup: file 644 "Env"
4107	PS1=X
4108stdin:
4109	echo abc def asjj sadjhasdjh asdjhasd
4110	fc -e - -g a=FooBAR
4111expected-stdout:
4112	abc def asjj sadjhasdjh asdjhasd
4113	FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd
4114expected-stderr-pattern:
4115	/^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/
4116---
4117name: history-subst-5
4118description:
4119	Make sure searches don't find current (fc) command
4120	(ksh88/ksh93 don't have the ? prefix thing so they fail this test)
4121need-ctty: yes
4122arguments: !-i!
4123env-setup: !ENV=./Env!HISTFILE=hist.file!
4124file-setup: file 644 "Env"
4125	PS1=X
4126stdin:
4127	echo abc def
4128	echo ghi jkl
4129	fc -e - abc=AB \?abc
4130expected-stdout:
4131	abc def
4132	ghi jkl
4133	AB def
4134expected-stderr-pattern:
4135	/^X*echo AB def\nX*$/
4136---
4137name: history-ed-1-old
4138description:
4139	Basic (ed) editing works (assumes you have generic ed editor
4140	that prints no prompts). This is for oldish ed(1) which write
4141	the character count to stdout.
4142category: stdout-ed
4143need-ctty: yes
4144need-pass: no
4145arguments: !-i!
4146env-setup: !ENV=./Env!HISTFILE=hist.file!
4147file-setup: file 644 "Env"
4148	PS1=X
4149stdin:
4150	echo abc def
4151	fc echo
4152	s/abc/FOOBAR/
4153	w
4154	q
4155expected-stdout:
4156	abc def
4157	13
4158	16
4159	FOOBAR def
4160expected-stderr-pattern:
4161	/^X*echo FOOBAR def\nX*$/
4162---
4163name: history-ed-2-old
4164description:
4165	Correct command is edited when number given
4166category: stdout-ed
4167need-ctty: yes
4168need-pass: no
4169arguments: !-i!
4170env-setup: !ENV=./Env!HISTFILE=hist.file!
4171file-setup: file 644 "Env"
4172	PS1=X
4173stdin:
4174	echo line 1
4175	echo line 2 is here
4176	echo line 3
4177	echo line 4
4178	fc 2
4179	s/is here/is changed/
4180	w
4181	q
4182expected-stdout:
4183	line 1
4184	line 2 is here
4185	line 3
4186	line 4
4187	20
4188	23
4189	line 2 is changed
4190expected-stderr-pattern:
4191	/^X*echo line 2 is changed\nX*$/
4192---
4193name: history-ed-3-old
4194description:
4195	Newly created multi line commands show up as single command
4196	in history.
4197	(ksh88 fails 'cause it lists the fc command)
4198category: stdout-ed
4199need-ctty: yes
4200need-pass: no
4201arguments: !-i!
4202env-setup: !ENV=./Env!HISTFILE=hist.file!
4203file-setup: file 644 "Env"
4204	PS1=X
4205stdin:
4206	echo abc def
4207	fc echo
4208	s/abc/FOOBAR/
4209	$a
4210	echo a new line
4211	.
4212	w
4213	q
4214	fc -l
4215expected-stdout:
4216	abc def
4217	13
4218	32
4219	FOOBAR def
4220	a new line
4221	1	echo abc def
4222	2	echo FOOBAR def
4223		echo a new line
4224expected-stderr-pattern:
4225	/^X*echo FOOBAR def\necho a new line\nX*$/
4226---
4227name: history-ed-1
4228description:
4229	Basic (ed) editing works (assumes you have generic ed editor
4230	that prints no prompts). This is for newish ed(1) and stderr.
4231category: !no-stderr-ed
4232need-ctty: yes
4233need-pass: no
4234arguments: !-i!
4235env-setup: !ENV=./Env!HISTFILE=hist.file!
4236file-setup: file 644 "Env"
4237	PS1=X
4238stdin:
4239	echo abc def
4240	fc echo
4241	s/abc/FOOBAR/
4242	w
4243	q
4244expected-stdout:
4245	abc def
4246	FOOBAR def
4247expected-stderr-pattern:
4248	/^X*13\n16\necho FOOBAR def\nX*$/
4249---
4250name: history-ed-2
4251description:
4252	Correct command is edited when number given
4253category: !no-stderr-ed
4254need-ctty: yes
4255need-pass: no
4256arguments: !-i!
4257env-setup: !ENV=./Env!HISTFILE=hist.file!
4258file-setup: file 644 "Env"
4259	PS1=X
4260stdin:
4261	echo line 1
4262	echo line 2 is here
4263	echo line 3
4264	echo line 4
4265	fc 2
4266	s/is here/is changed/
4267	w
4268	q
4269expected-stdout:
4270	line 1
4271	line 2 is here
4272	line 3
4273	line 4
4274	line 2 is changed
4275expected-stderr-pattern:
4276	/^X*20\n23\necho line 2 is changed\nX*$/
4277---
4278name: history-ed-3
4279description:
4280	Newly created multi line commands show up as single command
4281	in history.
4282category: !no-stderr-ed
4283need-ctty: yes
4284need-pass: no
4285arguments: !-i!
4286env-setup: !ENV=./Env!HISTFILE=hist.file!
4287file-setup: file 644 "Env"
4288	PS1=X
4289stdin:
4290	echo abc def
4291	fc echo
4292	s/abc/FOOBAR/
4293	$a
4294	echo a new line
4295	.
4296	w
4297	q
4298	fc -l
4299expected-stdout:
4300	abc def
4301	FOOBAR def
4302	a new line
4303	1	echo abc def
4304	2	echo FOOBAR def
4305		echo a new line
4306expected-stderr-pattern:
4307	/^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
4308---
4309name: IFS-space-1
4310description:
4311	Simple test, default IFS
4312stdin:
4313	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4314	set -- A B C
4315	showargs 1 $*
4316	showargs 2 "$*"
4317	showargs 3 $@
4318	showargs 4 "$@"
4319expected-stdout:
4320	<1> <A> <B> <C> .
4321	<2> <A B C> .
4322	<3> <A> <B> <C> .
4323	<4> <A> <B> <C> .
4324---
4325name: IFS-colon-1
4326description:
4327	Simple test, IFS=:
4328stdin:
4329	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4330	IFS=:
4331	set -- A B C
4332	showargs 1 $*
4333	showargs 2 "$*"
4334	showargs 3 $@
4335	showargs 4 "$@"
4336expected-stdout:
4337	<1> <A> <B> <C> .
4338	<2> <A:B:C> .
4339	<3> <A> <B> <C> .
4340	<4> <A> <B> <C> .
4341---
4342name: IFS-null-1
4343description:
4344	Simple test, IFS=""
4345stdin:
4346	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4347	IFS=""
4348	set -- A B C
4349	showargs 1 $*
4350	showargs 2 "$*"
4351	showargs 3 $@
4352	showargs 4 "$@"
4353expected-stdout:
4354	<1> <A> <B> <C> .
4355	<2> <ABC> .
4356	<3> <A> <B> <C> .
4357	<4> <A> <B> <C> .
4358---
4359name: IFS-space-colon-1
4360description:
4361	Simple test, IFS=<white-space>:
4362stdin:
4363	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4364	IFS="$IFS:"
4365	set --
4366	showargs 1 $*
4367	showargs 2 "$*"
4368	showargs 3 $@
4369	showargs 4 "$@"
4370	showargs 5 : "$@"
4371expected-stdout:
4372	<1> .
4373	<2> <> .
4374	<3> .
4375	<4> .
4376	<5> <:> .
4377---
4378name: IFS-space-colon-2
4379description:
4380	Simple test, IFS=<white-space>:
4381	AT&T ksh fails this, POSIX says the test is correct.
4382stdin:
4383	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4384	IFS="$IFS:"
4385	set --
4386	showargs :"$@"
4387expected-stdout:
4388	<:> .
4389---
4390name: IFS-space-colon-4
4391description:
4392	Simple test, IFS=<white-space>:
4393stdin:
4394	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4395	IFS="$IFS:"
4396	set --
4397	showargs "$@$@"
4398expected-stdout:
4399	.
4400---
4401name: IFS-space-colon-5
4402description:
4403	Simple test, IFS=<white-space>:
4404	Don't know what POSIX thinks of this.  AT&T ksh does not do this.
4405stdin:
4406	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4407	IFS="$IFS:"
4408	set --
4409	showargs "${@:-}"
4410expected-stdout:
4411	<> .
4412---
4413name: IFS-subst-1
4414description:
4415	Simple test, IFS=<white-space>:
4416stdin:
4417	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4418	IFS="$IFS:"
4419	x=":b: :"
4420	echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4421	echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo
4422	showargs 3 $x
4423	showargs 4 :b::
4424	x="a:b:"
4425	echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4426	showargs 6 $x
4427	x="a::c"
4428	echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4429	showargs 8 $x
4430	echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo
4431	showargs 10 ${FOO-`echo -n h:i`th:ere}
4432	showargs 11 "${FOO-`echo -n h:i`th:ere}"
4433	x=" A :  B::D"
4434	echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4435	showargs 13 $x
4436expected-stdout:
4437	1: [] [b] []
4438	2: [:b::]
4439	<3> <> <b> <> .
4440	<4> <:b::> .
4441	5: [a] [b]
4442	<6> <a> <b> .
4443	7: [a] [] [c]
4444	<8> <a> <> <c> .
4445	9: [h] [ith] [ere]
4446	<10> <h> <ith> <ere> .
4447	<11> <h:ith:ere> .
4448	12: [A] [B] [] [D]
4449	<13> <A> <B> <> <D> .
4450---
4451name: IFS-subst-2
4452description:
4453	Check leading whitespace after trim does not make a field
4454stdin:
4455	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4456	x="X 1 2"
4457	showargs 1 shift ${x#X}
4458expected-stdout:
4459	<1> <shift> <1> <2> .
4460---
4461name: IFS-subst-3-arr
4462description:
4463	Check leading IFS non-whitespace after trim does make a field
4464	but leading IFS whitespace does not, nor empty replacements
4465stdin:
4466	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4467	showargs 0 ${-+}
4468	IFS=:
4469	showargs 1 ${-+:foo:bar}
4470	IFS=' '
4471	showargs 2 ${-+ foo bar}
4472expected-stdout:
4473	<0> .
4474	<1> <> <foo> <bar> .
4475	<2> <foo> <bar> .
4476---
4477name: IFS-subst-3-ass
4478description:
4479	Check non-field semantics
4480stdin:
4481	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4482	showargs 0 x=${-+}
4483	IFS=:
4484	showargs 1 x=${-+:foo:bar}
4485	IFS=' '
4486	showargs 2 x=${-+ foo bar}
4487expected-stdout:
4488	<0> <x=> .
4489	<1> <x=> <foo> <bar> .
4490	<2> <x=> <foo> <bar> .
4491---
4492name: IFS-subst-3-lcl
4493description:
4494	Check non-field semantics, smaller corner case (LP#1381965)
4495stdin:
4496	set -x
4497	local regex=${2:-}
4498	exit 1
4499expected-exit: e != 0
4500expected-stderr-pattern:
4501	/regex=/
4502---
4503name: IFS-subst-4-1
4504description:
4505	reported by mikeserv
4506stdin:
4507	pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4508	a='space divded  argument
4509	here'
4510	IFS=\  ; set -- $a
4511	IFS= ; q="$*" ; nq=$*
4512	pfn "$*" $* "$q" "$nq"
4513	[ "$q" = "$nq" ] && echo =true || echo =false
4514expected-stdout:
4515	<spacedivdedargument
4516	here>
4517	<space>
4518	<divded>
4519	<argument
4520	here>
4521	<spacedivdedargument
4522	here>
4523	<spacedivdedargument
4524	here>
4525	=true
4526---
4527name: IFS-subst-4-2
4528description:
4529	extended testsuite based on problem by mikeserv
4530stdin:
4531	pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4532	a='space divded  argument
4533	here'
4534	IFS=\  ; set -- $a
4535	IFS= ; q="$@" ; nq=$@
4536	pfn "$*" $* "$q" "$nq"
4537	[ "$q" = "$nq" ] && echo =true || echo =false
4538expected-stdout:
4539	<spacedivdedargument
4540	here>
4541	<space>
4542	<divded>
4543	<argument
4544	here>
4545	<space divded argument
4546	here>
4547	<space divded argument
4548	here>
4549	=true
4550---
4551name: IFS-subst-4-3
4552description:
4553	extended testsuite based on problem by mikeserv
4554stdin:
4555	pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4556	a='space divded  argument
4557	here'
4558	IFS=\ ; set -- $a; IFS=
4559	qs="$*"
4560	nqs=$*
4561	qk="$@"
4562	nqk=$@
4563	print -nr -- '= qs '; pfn "$qs"
4564	print -nr -- '=nqs '; pfn "$nqs"
4565	print -nr -- '= qk '; pfn "$qk"
4566	print -nr -- '=nqk '; pfn "$nqk"
4567	print -nr -- '~ qs '; pfn "$*"
4568	print -nr -- '~nqs '; pfn $*
4569	print -nr -- '~ qk '; pfn "$@"
4570	print -nr -- '~nqk '; pfn $@
4571expected-stdout:
4572	= qs <spacedivdedargument
4573	here>
4574	=nqs <spacedivdedargument
4575	here>
4576	= qk <space divded argument
4577	here>
4578	=nqk <space divded argument
4579	here>
4580	~ qs <spacedivdedargument
4581	here>
4582	~nqs <space>
4583	<divded>
4584	<argument
4585	here>
4586	~ qk <space>
4587	<divded>
4588	<argument
4589	here>
4590	~nqk <space>
4591	<divded>
4592	<argument
4593	here>
4594---
4595name: IFS-subst-4-4
4596description:
4597	extended testsuite based on problem by mikeserv
4598stdin:
4599	pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4600	a='space divded  argument
4601	here'
4602	IFS=\ ; set -- $a; IFS=
4603	qs="$*"
4604	print -nr -- '= qs '; pfn "$qs"
4605	print -nr -- '~ qs '; pfn "$*"
4606	nqs=$*
4607	print -nr -- '=nqs '; pfn "$nqs"
4608	print -nr -- '~nqs '; pfn $*
4609	qk="$@"
4610	print -nr -- '= qk '; pfn "$qk"
4611	print -nr -- '~ qk '; pfn "$@"
4612	nqk=$@
4613	print -nr -- '=nqk '; pfn "$nqk"
4614	print -nr -- '~nqk '; pfn $@
4615expected-stdout:
4616	= qs <spacedivdedargument
4617	here>
4618	~ qs <spacedivdedargument
4619	here>
4620	=nqs <spacedivdedargument
4621	here>
4622	~nqs <space>
4623	<divded>
4624	<argument
4625	here>
4626	= qk <space divded argument
4627	here>
4628	~ qk <space>
4629	<divded>
4630	<argument
4631	here>
4632	=nqk <space divded argument
4633	here>
4634	~nqk <space>
4635	<divded>
4636	<argument
4637	here>
4638---
4639name: IFS-subst-4-4p
4640description:
4641	extended testsuite based on problem by mikeserv
4642stdin:
4643	pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4644	a='space divded  argument
4645	here'
4646	IFS=\ ; set -- $a; IFS=
4647	unset v
4648	qs=${v:-"$*"}
4649	print -nr -- '= qs '; pfn "$qs"
4650	print -nr -- '~ qs '; pfn ${v:-"$*"}
4651	nqs=${v:-$*}
4652	print -nr -- '=nqs '; pfn "$nqs"
4653	print -nr -- '~nqs '; pfn ${v:-$*}
4654	qk=${v:-"$@"}
4655	print -nr -- '= qk '; pfn "$qk"
4656	print -nr -- '~ qk '; pfn ${v:-"$@"}
4657	nqk=${v:-$@}
4658	print -nr -- '=nqk '; pfn "$nqk"
4659	print -nr -- '~nqk '; pfn ${v:-$@}
4660expected-stdout:
4661	= qs <spacedivdedargument
4662	here>
4663	~ qs <spacedivdedargument
4664	here>
4665	=nqs <spacedivdedargument
4666	here>
4667	~nqs <space>
4668	<divded>
4669	<argument
4670	here>
4671	= qk <space divded argument
4672	here>
4673	~ qk <space>
4674	<divded>
4675	<argument
4676	here>
4677	=nqk <space divded argument
4678	here>
4679	~nqk <space>
4680	<divded>
4681	<argument
4682	here>
4683---
4684name: IFS-subst-4-5
4685description:
4686	extended testsuite based on problem by mikeserv
4687stdin:
4688	pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4689	a='space divded  argument
4690	here'
4691	IFS=\ ; set -- $a; IFS=,
4692	qs="$*"
4693	print -nr -- '= qs '; pfn "$qs"
4694	print -nr -- '~ qs '; pfn "$*"
4695	nqs=$*
4696	print -nr -- '=nqs '; pfn "$nqs"
4697	print -nr -- '~nqs '; pfn $*
4698	qk="$@"
4699	print -nr -- '= qk '; pfn "$qk"
4700	print -nr -- '~ qk '; pfn "$@"
4701	nqk=$@
4702	print -nr -- '=nqk '; pfn "$nqk"
4703	print -nr -- '~nqk '; pfn $@
4704expected-stdout:
4705	= qs <space,divded,argument
4706	here>
4707	~ qs <space,divded,argument
4708	here>
4709	=nqs <space,divded,argument
4710	here>
4711	~nqs <space>
4712	<divded>
4713	<argument
4714	here>
4715	= qk <space divded argument
4716	here>
4717	~ qk <space>
4718	<divded>
4719	<argument
4720	here>
4721	=nqk <space divded argument
4722	here>
4723	~nqk <space>
4724	<divded>
4725	<argument
4726	here>
4727---
4728name: IFS-subst-4-5p
4729description:
4730	extended testsuite based on problem by mikeserv
4731stdin:
4732	pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4733	a='space divded  argument
4734	here'
4735	IFS=\ ; set -- $a; IFS=,
4736	unset v
4737	qs=${v:-"$*"}
4738	print -nr -- '= qs '; pfn "$qs"
4739	print -nr -- '~ qs '; pfn ${v:-"$*"}
4740	nqs=${v:-$*}
4741	print -nr -- '=nqs '; pfn "$nqs"
4742	print -nr -- '~nqs '; pfn ${v:-$*}
4743	qk=${v:-"$@"}
4744	print -nr -- '= qk '; pfn "$qk"
4745	print -nr -- '~ qk '; pfn ${v:-"$@"}
4746	nqk=${v:-$@}
4747	print -nr -- '=nqk '; pfn "$nqk"
4748	print -nr -- '~nqk '; pfn ${v:-$@}
4749expected-stdout:
4750	= qs <space,divded,argument
4751	here>
4752	~ qs <space,divded,argument
4753	here>
4754	=nqs <space,divded,argument
4755	here>
4756	~nqs <space>
4757	<divded>
4758	<argument
4759	here>
4760	= qk <space divded argument
4761	here>
4762	~ qk <space>
4763	<divded>
4764	<argument
4765	here>
4766	=nqk <space divded argument
4767	here>
4768	~nqk <space>
4769	<divded>
4770	<argument
4771	here>
4772---
4773name: IFS-subst-5
4774description:
4775	extended testsuite based on IFS-subst-3
4776	differs slightly from ksh93:
4777	- omit trailing field in a3zna, a7ina (unquoted $@ expansion)
4778	- has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4779	differs slightly from bash:
4780	- omit leading field in a5ins, a7ina (IFS_NWS unquoted expansion)
4781	differs slightly from zsh:
4782	- differs in assignment, not expansion; probably zsh bug
4783	- has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4784	'emulate sh' zsh has extra fields in
4785	- a5ins (IFS_NWS unquoted $*)
4786	- b5ins, matching mksh’s
4787	!!WARNING!! more to come: http://austingroupbugs.net/view.php?id=888
4788stdin:
4789	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4790		IFS=; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4791	echo '=a1zns'
4792	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4793		IFS=; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4794	echo '=a2zqs'
4795	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4796		IFS=; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4797	echo '=a3zna'
4798	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4799		IFS=; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4800	echo '=a4zqa'
4801	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4802		IFS=,; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4803	echo '=a5ins'
4804	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4805		IFS=,; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4806	echo '=a6iqs'
4807	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4808		IFS=,; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4809	echo '=a7ina'
4810	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4811		IFS=,; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4812	echo '=a8iqa'
4813	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4814		IFS=; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4815	echo '=b1zns'
4816	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4817		IFS=; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4818	echo '=b2zqs'
4819	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4820		IFS=; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4821	echo '=b3zna'
4822	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4823		IFS=; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4824	echo '=b4zqa'
4825	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4826		IFS=,; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4827	echo '=b5ins'
4828	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4829		IFS=,; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4830	echo '=b6iqs'
4831	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4832		IFS=,; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4833	echo '=b7ina'
4834	"$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4835		IFS=,; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4836	echo '=b8iqa'
4837expected-stdout:
4838	[2]
4839	<2>
4840	=a1zns
4841	[2]
4842	<2>
4843	=a2zqs
4844	[2]
4845	< 2 >
4846	=a3zna
4847	[]
4848	[2]
4849	[]
4850	< 2 >
4851	=a4zqa
4852	[2]
4853	<,2,>
4854	=a5ins
4855	[,2,]
4856	<,2,>
4857	=a6iqs
4858	[2]
4859	< 2 >
4860	=a7ina
4861	[]
4862	[2]
4863	[]
4864	< 2 >
4865	=a8iqa
4866	[A]
4867	[B]
4868	[C]
4869	<ABC>
4870	=b1zns
4871	[ABC]
4872	<ABC>
4873	=b2zqs
4874	[A]
4875	[B]
4876	[C]
4877	<A B   C>
4878	=b3zna
4879	[A]
4880	[B]
4881	[]
4882	[]
4883	[C]
4884	<A B   C>
4885	=b4zqa
4886	[A]
4887	[B]
4888	[]
4889	[]
4890	[C]
4891	<A,B,,,C>
4892	=b5ins
4893	[A,B,,,C]
4894	<A,B,,,C>
4895	=b6iqs
4896	[A]
4897	[B]
4898	[]
4899	[]
4900	[C]
4901	<A B   C>
4902	=b7ina
4903	[A]
4904	[B]
4905	[]
4906	[]
4907	[C]
4908	<A B   C>
4909	=b8iqa
4910---
4911name: IFS-subst-6
4912description:
4913	Regression wrt. vector expansion in trim
4914stdin:
4915	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4916	IFS=
4917	x=abc
4918	set -- a b
4919	showargs ${x#$*}
4920expected-stdout:
4921	<c> .
4922---
4923name: IFS-subst-7
4924description:
4925	ksh93 bug wrt. vector expansion in trim
4926stdin:
4927	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4928	IFS="*"
4929	a=abcd
4930	set -- '' c
4931	showargs "$*" ${a##"$*"}
4932expected-stdout:
4933	<*c> <abcd> .
4934---
4935name: IFS-subst-8
4936description:
4937	http://austingroupbugs.net/view.php?id=221
4938stdin:
4939	n() { echo "$#"; }; n "${foo-$@}"
4940expected-stdout:
4941	1
4942---
4943name: IFS-subst-9
4944description:
4945	Scalar context for $*/$@ in [[ and case
4946stdin:
4947	"$__progname" -c 'IFS=; set a b; [[ $* = "$1$2" ]]; echo 1 $?' sh a b
4948	"$__progname" -c 'IFS=; [[ $* = ab ]]; echo 2 "$?"' sh a b
4949	"$__progname" -c 'IFS=; [[ "$*" = ab ]]; echo 3 "$?"' sh a b
4950	"$__progname" -c 'IFS=; [[ $* = a ]]; echo 4 "$?"' sh a b
4951	"$__progname" -c 'IFS=; [[ "$*" = a ]]; echo 5 "$?"' sh a b
4952	"$__progname" -c 'IFS=; [[ "$@" = a ]]; echo 6 "$?"' sh a b
4953	"$__progname" -c 'IFS=; case "$@" in a) echo 7 a;; ab) echo 7 b;; a\ b) echo 7 ok;; esac' sh a b
4954	"$__progname" -c 'IFS=; case $* in a) echo 8 a;; ab) echo 8 ok;; esac' sh a b
4955	"$__progname" -c 'pfsp() { for s_arg in "$@"; do print -nr -- "<$s_arg> "; done; print .; }; IFS=; star=$* at="$@"; pfsp 9 "$star" "$at"' sh a b
4956expected-stdout:
4957	1 0
4958	2 0
4959	3 0
4960	4 1
4961	5 1
4962	6 1
4963	7 ok
4964	8 ok
4965	<9> <ab> <a b> .
4966---
4967name: IFS-subst-10
4968description:
4969	Scalar context in ${var=$subst}
4970stdin:
4971	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4972	set -- one "two three" four
4973	unset -v var
4974	save_IFS=$IFS
4975	IFS=
4976	set -- ${var=$*}
4977	IFS=$save_IFS
4978	echo "var=$var"
4979	showargs "$@"
4980expected-stdout:
4981	var=onetwo threefour
4982	<onetwo threefour> .
4983---
4984name: IFS-arith-1
4985description:
4986	http://austingroupbugs.net/view.php?id=832
4987stdin:
4988	${ZSH_VERSION+false} || emulate sh
4989	${BASH_VERSION+set -o posix}
4990	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4991	IFS=0
4992	showargs $((1230456))
4993expected-stdout:
4994	<123> <456> .
4995---
4996name: integer-base-err-1
4997description:
4998	Can't have 0 base (causes shell to exit)
4999expected-exit: e != 0
5000stdin:
5001	typeset -i i
5002	i=3
5003	i=0#4
5004	echo $i
5005expected-stderr-pattern:
5006	/^.*:.*0#4.*\n$/
5007---
5008name: integer-base-err-2
5009description:
5010	Can't have multiple bases in a 'constant' (causes shell to exit)
5011	(ksh88 fails this test)
5012expected-exit: e != 0
5013stdin:
5014	typeset -i i
5015	i=3
5016	i=2#110#11
5017	echo $i
5018expected-stderr-pattern:
5019	/^.*:.*2#110#11.*\n$/
5020---
5021name: integer-base-err-3
5022description:
5023	Syntax errors in expressions and effects on bases
5024	(interactive so errors don't cause exits)
5025	(ksh88 fails this test - shell exits, even with -i)
5026need-ctty: yes
5027arguments: !-i!
5028stdin:
5029	PS1= # minimise prompt hassles
5030	typeset -i4 a=10
5031	typeset -i a=2+
5032	echo $a
5033	typeset -i4 a=10
5034	typeset -i2 a=2+
5035	echo $a
5036expected-stderr-pattern:
5037	/^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/
5038expected-stdout:
5039	4#22
5040	4#22
5041---
5042name: integer-base-err-4
5043description:
5044	Are invalid digits (according to base) errors?
5045	(ksh93 fails this test)
5046expected-exit: e != 0
5047stdin:
5048	typeset -i i;
5049	i=3#4
5050expected-stderr-pattern:
5051	/^([#\$] )?.*:.*3#4.*\n$/
5052---
5053name: integer-base-1
5054description:
5055	Missing number after base is treated as 0.
5056stdin:
5057	typeset -i i
5058	i=3
5059	i=2#
5060	echo $i
5061expected-stdout:
5062	0
5063---
5064name: integer-base-2
5065description:
5066	Check 'stickyness' of base in various situations
5067stdin:
5068	typeset -i i=8
5069	echo $i
5070	echo ---------- A
5071	typeset -i4 j=8
5072	echo $j
5073	echo ---------- B
5074	typeset -i k=8
5075	typeset -i4 k=8
5076	echo $k
5077	echo ---------- C
5078	typeset -i4 l
5079	l=3#10
5080	echo $l
5081	echo ---------- D
5082	typeset -i m
5083	m=3#10
5084	echo $m
5085	echo ---------- E
5086	n=2#11
5087	typeset -i n
5088	echo $n
5089	n=10
5090	echo $n
5091	echo ---------- F
5092	typeset -i8 o=12
5093	typeset -i4 o
5094	echo $o
5095	echo ---------- G
5096	typeset -i p
5097	let p=8#12
5098	echo $p
5099expected-stdout:
5100	8
5101	---------- A
5102	4#20
5103	---------- B
5104	4#20
5105	---------- C
5106	4#3
5107	---------- D
5108	3#10
5109	---------- E
5110	2#11
5111	2#1010
5112	---------- F
5113	4#30
5114	---------- G
5115	8#12
5116---
5117name: integer-base-3
5118description:
5119	More base parsing (hmm doesn't test much..)
5120stdin:
5121	typeset -i aa
5122	aa=1+12#10+2
5123	echo $aa
5124	typeset -i bb
5125	bb=1+$aa
5126	echo $bb
5127	typeset -i bb
5128	bb=$aa
5129	echo $bb
5130	typeset -i cc
5131	cc=$aa
5132	echo $cc
5133expected-stdout:
5134	15
5135	16
5136	15
5137	15
5138---
5139name: integer-base-4
5140description:
5141	Check that things not declared as integers are not made integers,
5142	also, check if base is not reset by -i with no arguments.
5143	(ksh93 fails - prints 10#20 - go figure)
5144stdin:
5145	xx=20
5146	let xx=10
5147	typeset -i | grep '^xx='
5148	typeset -i4 a=10
5149	typeset -i a=20
5150	echo $a
5151expected-stdout:
5152	4#110
5153---
5154name: integer-base-5
5155description:
5156	More base stuff
5157stdin:
5158	typeset -i4 a=3#10
5159	echo $a
5160	echo --
5161	typeset -i j=3
5162	j='~3'
5163	echo $j
5164	echo --
5165	typeset -i k=1
5166	x[k=k+1]=3
5167	echo $k
5168	echo --
5169	typeset -i l
5170	for l in 1 2+3 4; do echo $l; done
5171expected-stdout:
5172	4#3
5173	--
5174	-4
5175	--
5176	2
5177	--
5178	1
5179	5
5180	4
5181---
5182name: integer-base-6
5183description:
5184	Even more base stuff
5185	(ksh93 fails this test - prints 0)
5186stdin:
5187	typeset -i7 i
5188	i=
5189	echo $i
5190expected-stdout:
5191	7#0
5192---
5193name: integer-base-7
5194description:
5195	Check that non-integer parameters don't get bases assigned
5196stdin:
5197	echo $(( zz = 8#100 ))
5198	echo $zz
5199expected-stdout:
5200	64
5201	64
5202---
5203name: integer-base-8
5204description:
5205	Check that base-36 works (full span)
5206stdin:
5207	echo 1:$((36#109AZ)).
5208	typeset -i36 x=1691675
5209	echo 2:$x.
5210	typeset -Uui36 x
5211	echo 3:$x.
5212expected-stdout:
5213	1:1691675.
5214	2:36#109az.
5215	3:36#109AZ.
5216---
5217name: integer-base-check-flat
5218description:
5219	Check behaviour does not match POSuX (except if set -o posix),
5220	because a not type-safe scripting language has *no* business
5221	interpreting the string "010" as octal number eight (dangerous).
5222stdin:
5223	echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" .
5224	echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" .
5225	echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" .
5226expected-stdout:
5227	1 :10/10,16: .
5228	2 :10/8,16: .
5229	3 :10/10,16: .
5230---
5231name: integer-base-check-numeric-from-1
5232description:
5233	Check behaviour for base one
5234category: !shell:ebcdic-yes
5235stdin:
5236	echo 1:$((1#1))0.
5237expected-stdout:
5238	1:490.
5239---
5240name: integer-base-check-numeric-from-1-ebcdic
5241description:
5242	Check behaviour for base one
5243category: !shell:ebcdic-no
5244stdin:
5245	echo 1:$((1#1))0.
5246expected-stdout:
5247	1:2410.
5248---
5249name: integer-base-check-numeric-from-2
5250description:
5251	Check behaviour for base two to 36, and that 37 degrades to 10
5252stdin:
5253	i=1
5254	while (( ++i <= 37 )); do
5255		eval 'echo '$i':$(('$i'#10)).'
5256	done
5257	echo 37:$($__progname -c 'echo $((37#10))').$?:
5258expected-stdout:
5259	2:2.
5260	3:3.
5261	4:4.
5262	5:5.
5263	6:6.
5264	7:7.
5265	8:8.
5266	9:9.
5267	10:10.
5268	11:11.
5269	12:12.
5270	13:13.
5271	14:14.
5272	15:15.
5273	16:16.
5274	17:17.
5275	18:18.
5276	19:19.
5277	20:20.
5278	21:21.
5279	22:22.
5280	23:23.
5281	24:24.
5282	25:25.
5283	26:26.
5284	27:27.
5285	28:28.
5286	29:29.
5287	30:30.
5288	31:31.
5289	32:32.
5290	33:33.
5291	34:34.
5292	35:35.
5293	36:36.
5294	37:10.
5295	37:10.0:
5296---
5297name: integer-base-check-numeric-to-1
5298description:
5299	Check behaviour for base one
5300category: !shell:ebcdic-yes
5301stdin:
5302	i=1
5303	typeset -Uui$i x=0x40
5304	eval "typeset -i10 y=$x"
5305	print $i:$x.$y.
5306expected-stdout:
5307	1:1#@.64.
5308---
5309name: integer-base-check-numeric-to-1-ebcdic
5310description:
5311	Check behaviour for base one
5312category: !shell:ebcdic-no
5313stdin:
5314	i=1
5315	typeset -Uui$i x=0x7C
5316	eval "typeset -i10 y=$x"
5317	print $i:$x.$y.
5318expected-stdout:
5319	1:1#@.124.
5320---
5321name: integer-base-check-numeric-to-2
5322description:
5323	Check behaviour for base two to 36, and that 37 degrades to 10
5324stdin:
5325	i=1
5326	while (( ++i <= 37 )); do
5327		typeset -Uui$i x=0x40
5328		eval "typeset -i10 y=$x"
5329		print $i:$x.$y.
5330	done
5331expected-stdout:
5332	2:2#1000000.64.
5333	3:3#2101.64.
5334	4:4#1000.64.
5335	5:5#224.64.
5336	6:6#144.64.
5337	7:7#121.64.
5338	8:8#100.64.
5339	9:9#71.64.
5340	10:64.64.
5341	11:11#59.64.
5342	12:12#54.64.
5343	13:13#4C.64.
5344	14:14#48.64.
5345	15:15#44.64.
5346	16:16#40.64.
5347	17:17#3D.64.
5348	18:18#3A.64.
5349	19:19#37.64.
5350	20:20#34.64.
5351	21:21#31.64.
5352	22:22#2K.64.
5353	23:23#2I.64.
5354	24:24#2G.64.
5355	25:25#2E.64.
5356	26:26#2C.64.
5357	27:27#2A.64.
5358	28:28#28.64.
5359	29:29#26.64.
5360	30:30#24.64.
5361	31:31#22.64.
5362	32:32#20.64.
5363	33:33#1V.64.
5364	34:34#1U.64.
5365	35:35#1T.64.
5366	36:36#1S.64.
5367	37:64.64.
5368---
5369name: integer-arithmetic-span
5370description:
5371	Check wraparound and size that is defined in mksh
5372category: int:32
5373stdin:
5374	echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)).
5375	echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)).
5376expected-stdout:
5377	s:-2147483648.-1.0.
5378	u:2147483648.4294967295.0.
5379---
5380name: integer-arithmetic-span-64
5381description:
5382	Check wraparound and size that is defined in mksh
5383category: int:64
5384stdin:
5385	echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)).
5386	echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)).
5387expected-stdout:
5388	s:-9223372036854775808.-1.0.
5389	u:9223372036854775808.18446744073709551615.0.
5390---
5391name: integer-size-FAIL-to-detect
5392description:
5393	Notify the user that their ints are not 32 or 64 bit
5394category: int:u
5395stdin:
5396	:
5397---
5398name: lineno-stdin
5399description:
5400	See if $LINENO is updated and can be modified.
5401stdin:
5402	echo A $LINENO
5403	echo B $LINENO
5404	LINENO=20
5405	echo C $LINENO
5406expected-stdout:
5407	A 1
5408	B 2
5409	C 20
5410---
5411name: lineno-inc
5412description:
5413	See if $LINENO is set for .'d files.
5414file-setup: file 644 "dotfile"
5415	echo dot A $LINENO
5416	echo dot B $LINENO
5417	LINENO=20
5418	echo dot C $LINENO
5419stdin:
5420	echo A $LINENO
5421	echo B $LINENO
5422	. ./dotfile
5423expected-stdout:
5424	A 1
5425	B 2
5426	dot A 1
5427	dot B 2
5428	dot C 20
5429---
5430name: lineno-func
5431description:
5432	See if $LINENO is set for commands in a function.
5433stdin:
5434	echo A $LINENO
5435	echo B $LINENO
5436	bar() {
5437	    echo func A $LINENO
5438	    echo func B $LINENO
5439	}
5440	bar
5441	echo C $LINENO
5442expected-stdout:
5443	A 1
5444	B 2
5445	func A 4
5446	func B 5
5447	C 8
5448---
5449name: lineno-unset
5450description:
5451	See if unsetting LINENO makes it non-magic.
5452file-setup: file 644 "dotfile"
5453	echo dot A $LINENO
5454	echo dot B $LINENO
5455stdin:
5456	unset LINENO
5457	echo A $LINENO
5458	echo B $LINENO
5459	bar() {
5460	    echo func A $LINENO
5461	    echo func B $LINENO
5462	}
5463	bar
5464	. ./dotfile
5465	echo C $LINENO
5466expected-stdout:
5467	A
5468	B
5469	func A
5470	func B
5471	dot A
5472	dot B
5473	C
5474---
5475name: lineno-unset-use
5476description:
5477	See if unsetting LINENO makes it non-magic even
5478	when it is re-used.
5479file-setup: file 644 "dotfile"
5480	echo dot A $LINENO
5481	echo dot B $LINENO
5482stdin:
5483	unset LINENO
5484	LINENO=3
5485	echo A $LINENO
5486	echo B $LINENO
5487	bar() {
5488	    echo func A $LINENO
5489	    echo func B $LINENO
5490	}
5491	bar
5492	. ./dotfile
5493	echo C $LINENO
5494expected-stdout:
5495	A 3
5496	B 3
5497	func A 3
5498	func B 3
5499	dot A 3
5500	dot B 3
5501	C 3
5502---
5503name: lineno-trap
5504description:
5505	Check if LINENO is tracked in traps
5506stdin:
5507	fail() {
5508		echo "line <$1>"
5509		exit 1
5510	}
5511	trap 'fail $LINENO' INT ERR
5512	false
5513expected-stdout:
5514	line <6>
5515expected-exit: 1
5516---
5517name: lineno-eval-alias
5518description:
5519	Check if LINENO is trapped in eval and aliases
5520stdin:
5521	${ZSH_VERSION+false} || emulate sh; echo $LINENO
5522	echo $LINENO
5523	eval '	echo $LINENO
5524		echo $LINENO
5525		echo $LINENO'
5526	echo $LINENO
5527expected-stdout:
5528	1
5529	2
5530	3
5531	3
5532	3
5533	6
5534---
5535name: unknown-trap
5536description:
5537	Ensure unknown traps are not a syntax error
5538stdin:
5539	(
5540	trap "echo trap 1 executed" UNKNOWNSIGNAL || echo "foo"
5541	echo =1
5542	trap "echo trap 2 executed" UNKNOWNSIGNAL EXIT 999999 FNORD
5543	echo = $?
5544	) 2>&1 | sed "s^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]PROG"
5545expected-stdout:
5546	PROG: trap: bad signal 'UNKNOWNSIGNAL'
5547	foo
5548	=1
5549	PROG: trap: bad signal 'UNKNOWNSIGNAL'
5550	PROG: trap: bad signal '999999'
5551	PROG: trap: bad signal 'FNORD'
5552	= 1
5553	trap 2 executed
5554---
5555name: read-IFS-1
5556description:
5557	Simple test, default IFS
5558stdin:
5559	echo "A B " > IN
5560	unset x y z
5561	read x y z < IN
5562	echo 1: "x[$x] y[$y] z[$z]"
5563	echo 1a: ${z-z not set}
5564	read x < IN
5565	echo 2: "x[$x]"
5566expected-stdout:
5567	1: x[A] y[B] z[]
5568	1a:
5569	2: x[A B]
5570---
5571name: read-IFS-2
5572description:
5573	Complex tests, IFS either colon (IFS-NWS) or backslash (tricky)
5574stdin:
5575	n=0
5576	showargs() { print -nr "$1"; shift; for s_arg in "$@"; do print -nr -- " [$s_arg]"; done; print; }
5577	(IFS=\\ a=\<\\\>; showargs 3 $a)
5578	(IFS=: b=\<:\>; showargs 4 $b)
5579	print -r '<\>' | (IFS=\\ read f g; showargs 5 "$f" "$g")
5580	print -r '<\\>' | (IFS=\\ read f g; showargs 6 "$f" "$g")
5581	print '<\\\n>' | (IFS=\\ read f g; showargs 7 "$f" "$g")
5582	print -r '<\>' | (IFS=\\ read f; showargs 8 "$f")
5583	print -r '<\\>' | (IFS=\\ read f; showargs 9 "$f")
5584	print '<\\\n>' | (IFS=\\ read f; showargs 10 "$f")
5585	print -r '<\>' | (IFS=\\ read -r f g; showargs 11 "$f" "$g")
5586	print -r '<\\>' | (IFS=\\ read -r f g; showargs 12 "$f" "$g")
5587	print '<\\\n>' | (IFS=\\ read -r f g; showargs 13 "$f" "$g")
5588	print -r '<\>' | (IFS=\\ read -r f; showargs 14 "$f")
5589	print -r '<\\>' | (IFS=\\ read -r f; showargs 15 "$f")
5590	print '<\\\n>' | (IFS=\\ read -r f; showargs 16 "$f")
5591	print -r '<:>' | (IFS=: read f g; showargs 17 "$f" "$g")
5592	print -r '<::>' | (IFS=: read f g; showargs 18 "$f" "$g")
5593	print '<:\n>' | (IFS=: read f g; showargs 19 "$f" "$g")
5594	print -r '<:>' | (IFS=: read f; showargs 20 "$f")
5595	print -r '<::>' | (IFS=: read f; showargs 21 "$f")
5596	print '<:\n>' | (IFS=: read f; showargs 22 "$f")
5597	print -r '<:>' | (IFS=: read -r f g; showargs 23 "$f" "$g")
5598	print -r '<::>' | (IFS=: read -r f g; showargs 24 "$f" "$g")
5599	print '<:\n>' | (IFS=: read -r f g; showargs 25 "$f" "$g")
5600	print -r '<:>' | (IFS=: read -r f; showargs 26 "$f")
5601	print -r '<::>' | (IFS=: read -r f; showargs 27 "$f")
5602	print '<:\n>' | (IFS=: read -r f; showargs 28 "$f")
5603expected-stdout:
5604	3 [<] [>]
5605	4 [<] [>]
5606	5 [<] [>]
5607	6 [<] [>]
5608	7 [<>] []
5609	8 [<>]
5610	9 [<\>]
5611	10 [<>]
5612	11 [<] [>]
5613	12 [<] [\>]
5614	13 [<] []
5615	14 [<\>]
5616	15 [<\\>]
5617	16 [<]
5618	17 [<] [>]
5619	18 [<] [:>]
5620	19 [<] []
5621	20 [<:>]
5622	21 [<::>]
5623	22 [<]
5624	23 [<] [>]
5625	24 [<] [:>]
5626	25 [<] []
5627	26 [<:>]
5628	27 [<::>]
5629	28 [<]
5630---
5631name: read-ksh-1
5632description:
5633	If no var specified, REPLY is used
5634stdin:
5635	echo "abc" > IN
5636	read < IN
5637	echo "[$REPLY]";
5638expected-stdout:
5639	[abc]
5640---
5641name: read-regress-1
5642description:
5643	Check a regression of read
5644file-setup: file 644 "foo"
5645	foo bar
5646	baz
5647	blah
5648stdin:
5649	while read a b c; do
5650		read d
5651		break
5652	done <foo
5653	echo "<$a|$b|$c><$d>"
5654expected-stdout:
5655	<foo|bar|><baz>
5656---
5657name: read-delim-1
5658description:
5659	Check read with delimiters
5660stdin:
5661	emit() {
5662		print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0'
5663	}
5664	emit | while IFS= read -d "" foo; do print -r -- "<$foo>"; done
5665	emit | while read -d "" foo; do print -r -- "<$foo>"; done
5666	emit | while read -d "eh?" foo; do print -r -- "<$foo>"; done
5667expected-stdout:
5668	<foo bar	baz
5669	blah >
5670	<blub	blech
5671	myok meck >
5672	<foo bar	baz
5673	blah>
5674	<blub	blech
5675	myok meck>
5676	<foo bar	baz
5677	blah blub	bl>
5678	<ch
5679	myok m>
5680---
5681name: read-ext-1
5682description:
5683	Check read with number of bytes specified, and -A
5684stdin:
5685	print 'foo\nbar' >x1
5686	print -n x >x2
5687	print 'foo\\ bar baz' >x3
5688	x1a=u; read x1a <x1
5689	x1b=u; read -N-1 x1b <x1
5690	x2a=u; read x2a <x2; r2a=$?
5691	x2b=u; read -N2 x2c <x2; r2b=$?
5692	x2c=u; read -n2 x2c <x2; r2c=$?
5693	x3a=u; read -A x3a <x3
5694	print -r "x1a=<$x1a>"
5695	print -r "x1b=<$x1b>"
5696	print -r "x2a=$r2a<$x2a>"
5697	print -r "x2b=$r2b<$x2b>"
5698	print -r "x2c=$r2c<$x2c>"
5699	print -r "x3a=<${x3a[0]}|${x3a[1]}|${x3a[2]}>"
5700expected-stdout:
5701	x1a=<foo>
5702	x1b=<foo
5703	bar>
5704	x2a=1<x>
5705	x2b=1<u>
5706	x2c=0<x>
5707	x3a=<foo bar|baz|>
5708---
5709name: regression-1
5710description:
5711	Lex array code had problems with this.
5712stdin:
5713	echo foo[
5714	n=bar
5715	echo "hi[ $n ]=1"
5716expected-stdout:
5717	foo[
5718	hi[ bar ]=1
5719---
5720name: regression-2
5721description:
5722	When PATH is set before running a command, the new path is
5723	not used in doing the path search
5724		$ echo echo hi > /tmp/q ; chmod a+rx /tmp/q
5725		$ PATH=/tmp q
5726		q: not found
5727		$
5728	in comexec() the two lines
5729		while (*vp != NULL)
5730			(void) typeset(*vp++, xxx, 0);
5731	need to be moved out of the switch to before findcom() is
5732	called - I don't know what this will break.
5733stdin:
5734	: "${PWD:-`pwd 2> /dev/null`}"
5735	: "${PWD:?"PWD not set - cannot do test"}"
5736	mkdir Y
5737	cat > Y/xxxscript << EOF
5738	#!/bin/sh
5739	# Need to restore path so echo can be found (some shells don't have
5740	# it as a built-in)
5741	PATH=\$OLDPATH
5742	echo hi
5743	exit 0
5744	EOF
5745	chmod a+rx Y/xxxscript
5746	export OLDPATH="$PATH"
5747	PATH=$PWD/Y xxxscript
5748	exit $?
5749expected-stdout:
5750	hi
5751---
5752name: regression-6
5753description:
5754	Parsing of $(..) expressions is non-optimal.  It is
5755	impossible to have any parentheses inside the expression.
5756	I.e.,
5757		$ ksh -c 'echo $(echo \( )'
5758		no closing quote
5759		$ ksh -c 'echo $(echo "(" )'
5760		no closing quote
5761		$
5762	The solution is to hack the parsing clode in lex.c, the
5763	question is how to hack it: should any parentheses be
5764	escaped by a backslash, or should recursive parsing be done
5765	(so quotes could also be used to hide hem).  The former is
5766	easier, the later better...
5767stdin:
5768	echo $(echo \( )
5769	echo $(echo "(" )
5770expected-stdout:
5771	(
5772	(
5773---
5774name: regression-9
5775description:
5776	Continue in a for loop does not work right:
5777		for i in a b c ; do
5778			if [ $i = b ] ; then
5779				continue
5780			fi
5781			echo $i
5782		done
5783	Prints a forever...
5784stdin:
5785	first=yes
5786	for i in a b c ; do
5787		if [ $i = b ] ; then
5788			if [ $first = no ] ; then
5789				echo 'continue in for loop broken'
5790				break	# hope break isn't broken too :-)
5791			fi
5792			first=no
5793			continue
5794		fi
5795	done
5796	echo bye
5797expected-stdout:
5798	bye
5799---
5800name: regression-10
5801description:
5802	The following:
5803		set -- `false`
5804		echo $?
5805	should print 0 according to POSIX (dash, bash, ksh93, posh)
5806	but not 0 according to the getopt(1) manual page, ksh88, and
5807	Bourne sh (such as /bin/sh on Solaris).
5808	We honour POSIX except when -o sh is set.
5809category: shell:legacy-no
5810stdin:
5811	showf() {
5812		[[ -o posix ]]; FPOSIX=$((1-$?))
5813		[[ -o sh ]]; FSH=$((1-$?))
5814		echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5815	}
5816	set +o posix +o sh
5817	showf
5818	set -- `false`
5819	echo rv=$?
5820	set -o sh
5821	showf
5822	set -- `false`
5823	echo rv=$?
5824	set -o posix
5825	showf
5826	set -- `false`
5827	echo rv=$?
5828	set -o posix -o sh
5829	showf
5830	set -- `false`
5831	echo rv=$?
5832expected-stdout:
5833	FPOSIX=0 FSH=0 rv=0
5834	FPOSIX=0 FSH=1 rv=1
5835	FPOSIX=1 FSH=0 rv=0
5836	FPOSIX=1 FSH=1 rv=0
5837---
5838name: regression-10-legacy
5839description:
5840	The following:
5841		set -- `false`
5842		echo $?
5843	should print 0 according to POSIX (dash, bash, ksh93, posh)
5844	but not 0 according to the getopt(1) manual page, ksh88, and
5845	Bourne sh (such as /bin/sh on Solaris).
5846category: shell:legacy-yes
5847stdin:
5848	showf() {
5849		[[ -o posix ]]; FPOSIX=$((1-$?))
5850		[[ -o sh ]]; FSH=$((1-$?))
5851		echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5852	}
5853	set +o posix +o sh
5854	showf
5855	set -- `false`
5856	echo rv=$?
5857	set -o sh
5858	showf
5859	set -- `false`
5860	echo rv=$?
5861	set -o posix
5862	showf
5863	set -- `false`
5864	echo rv=$?
5865	set -o posix -o sh
5866	showf
5867	set -- `false`
5868	echo rv=$?
5869expected-stdout:
5870	FPOSIX=0 FSH=0 rv=1
5871	FPOSIX=0 FSH=1 rv=1
5872	FPOSIX=1 FSH=0 rv=0
5873	FPOSIX=1 FSH=1 rv=0
5874---
5875name: regression-11
5876description:
5877	The following:
5878		x=/foo/bar/blah
5879		echo ${x##*/}
5880	should echo blah but on some machines echos /foo/bar/blah.
5881stdin:
5882	x=/foo/bar/blah
5883	echo ${x##*/}
5884expected-stdout:
5885	blah
5886---
5887name: regression-12
5888description:
5889	Both of the following echos produce the same output under sh/ksh.att:
5890		#!/bin/sh
5891		x="foo	bar"
5892		echo "`echo \"$x\"`"
5893		echo "`echo "$x"`"
5894	pdksh produces different output for the former (foo instead of foo\tbar)
5895stdin:
5896	x="foo	bar"
5897	echo "`echo \"$x\"`"
5898	echo "`echo "$x"`"
5899expected-stdout:
5900	foo	bar
5901	foo	bar
5902---
5903name: regression-13
5904description:
5905	The following command hangs forever:
5906		$ (: ; cat /etc/termcap) | sleep 2
5907	This is because the shell forks a shell to run the (..) command
5908	and this shell has the pipe open.  When the sleep dies, the cat
5909	doesn't get a SIGPIPE 'cause a process (ie, the second shell)
5910	still has the pipe open.
5911
5912	NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading
5913	      commands from /etc/termcap..)
5914time-limit: 10
5915stdin:
5916	echo A line of text that will be duplicated quite a number of times.> t1
5917	cat t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  > t2
5918	cat t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  > t1
5919	cat t1 t1 t1 t1 > t2
5920	(: ; cat t2 2>/dev/null) | sleep 1
5921---
5922name: regression-14
5923description:
5924	The command
5925		$ (foobar) 2> /dev/null
5926	generates no output under /bin/sh, but pdksh produces the error
5927		foobar: not found
5928	Also, the command
5929		$ foobar 2> /dev/null
5930	generates an error under /bin/sh and pdksh, but AT&T ksh88 produces
5931	no error (redirected to /dev/null).
5932stdin:
5933	(you/should/not/see/this/error/1) 2> /dev/null
5934	you/should/not/see/this/error/2 2> /dev/null
5935	true
5936---
5937name: regression-15
5938description:
5939	The command
5940		$ whence foobar
5941	generates a blank line under pdksh and sets the exit status to 0.
5942	AT&T ksh88 generates no output and sets the exit status to 1.  Also,
5943	the command
5944		$ whence foobar cat
5945	generates no output under AT&T ksh88 (pdksh generates a blank line
5946	and /bin/cat).
5947stdin:
5948	whence does/not/exist > /dev/null
5949	echo 1: $?
5950	echo 2: $(whence does/not/exist | wc -l)
5951	echo 3: $(whence does/not/exist cat | wc -l)
5952expected-stdout:
5953	1: 1
5954	2: 0
5955	3: 0
5956---
5957name: regression-16
5958description:
5959	${var%%expr} seems to be broken in many places.  On the mips
5960	the commands
5961		$ read line < /etc/passwd
5962		$ echo $line
5963		root:0:1:...
5964		$ echo ${line%%:*}
5965		root
5966		$ echo $line
5967		root
5968		$
5969	change the value of line.  On sun4s & pas, the echo ${line%%:*} doesn't
5970	work.  Haven't checked elsewhere...
5971script:
5972	read x
5973	y=$x
5974	echo ${x%%:*}
5975	echo $x
5976stdin:
5977	root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5978expected-stdout:
5979	root
5980	root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5981---
5982name: regression-17
5983description:
5984	The command
5985		. /foo/bar
5986	should set the exit status to non-zero (sh and AT&T ksh88 do).
5987	XXX doting a non existent file is a fatal error for a script
5988stdin:
5989	. does/not/exist
5990expected-exit: e != 0
5991expected-stderr-pattern: /.?/
5992---
5993name: regression-19
5994description:
5995	Both of the following echos should produce the same thing, but don't:
5996		$ x=foo/bar
5997		$ echo ${x%/*}
5998		foo
5999		$ echo "${x%/*}"
6000		foo/bar
6001stdin:
6002	x=foo/bar
6003	echo "${x%/*}"
6004expected-stdout:
6005	foo
6006---
6007name: regression-21
6008description:
6009	backslash does not work as expected in case labels:
6010	$ x='-x'
6011	$ case $x in
6012	-\?) echo hi
6013	esac
6014	hi
6015	$ x='-?'
6016	$ case $x in
6017	-\\?) echo hi
6018	esac
6019	hi
6020	$
6021stdin:
6022	case -x in
6023	-\?)	echo fail
6024	esac
6025---
6026name: regression-22
6027description:
6028	Quoting backquotes inside backquotes doesn't work:
6029	$ echo `echo hi \`echo there\` folks`
6030	asks for more info.  sh and AT&T ksh88 both echo
6031	hi there folks
6032stdin:
6033	echo `echo hi \`echo there\` folks`
6034expected-stdout:
6035	hi there folks
6036---
6037name: regression-23
6038description:
6039	)) is not treated `correctly':
6040	    $ (echo hi ; (echo there ; echo folks))
6041	    missing ((
6042	    $
6043	instead of (as sh and ksh.att)
6044	    $ (echo hi ; (echo there ; echo folks))
6045	    hi
6046	    there
6047	    folks
6048	    $
6049stdin:
6050	( : ; ( : ; echo hi))
6051expected-stdout:
6052	hi
6053---
6054name: regression-25
6055description:
6056	Check reading stdin in a while loop.  The read should only read
6057	a single line, not a whole stdio buffer; the cat should get
6058	the rest.
6059stdin:
6060	(echo a; echo b) | while read x ; do
6061	    echo $x
6062	    cat > /dev/null
6063	done
6064expected-stdout:
6065	a
6066---
6067name: regression-26
6068description:
6069	Check reading stdin in a while loop.  The read should read both
6070	lines, not just the first.
6071script:
6072	a=
6073	while [ "$a" != xxx ] ; do
6074	    last=$x
6075	    read x
6076	    cat /dev/null | sed 's/x/y/'
6077	    a=x$a
6078	done
6079	echo $last
6080stdin:
6081	a
6082	b
6083expected-stdout:
6084	b
6085---
6086name: regression-27
6087description:
6088	The command
6089		. /does/not/exist
6090	should cause a script to exit.
6091stdin:
6092	. does/not/exist
6093	echo hi
6094expected-exit: e != 0
6095expected-stderr-pattern: /does\/not\/exist/
6096---
6097name: regression-28
6098description:
6099	variable assignements not detected well
6100stdin:
6101	a.x=1 echo hi
6102expected-exit: e != 0
6103expected-stderr-pattern: /a\.x=1/
6104---
6105name: regression-29
6106description:
6107	alias expansion different from AT&T ksh88
6108stdin:
6109	alias a='for ' b='i in'
6110	a b hi ; do echo $i ; done
6111expected-stdout:
6112	hi
6113---
6114name: regression-30
6115description:
6116	strange characters allowed inside ${...}
6117stdin:
6118	echo ${a{b}}
6119expected-exit: e != 0
6120expected-stderr-pattern: /.?/
6121---
6122name: regression-31
6123description:
6124	Does read handle partial lines correctly
6125script:
6126	a= ret=
6127	while [ "$a" != xxx ] ; do
6128	    read x y z
6129	    ret=$?
6130	    a=x$a
6131	done
6132	echo "[$x]"
6133	echo $ret
6134stdin: !
6135	a A aA
6136	b B Bb
6137	c
6138expected-stdout:
6139	[c]
6140	1
6141---
6142name: regression-32
6143description:
6144	Does read set variables to null at eof?
6145script:
6146	a=
6147	while [ "$a" != xxx ] ; do
6148	    read x y z
6149	    a=x$a
6150	done
6151	echo 1: ${x-x not set} ${y-y not set} ${z-z not set}
6152	echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null}
6153stdin:
6154	a A Aa
6155	b B Bb
6156expected-stdout:
6157	1:
6158	2:
6159---
6160name: regression-33
6161description:
6162	Does umask print a leading 0 when umask is 3 digits?
6163stdin:
6164	# on MiNT, the first umask call seems to fail
6165	umask 022
6166	# now, the test proper
6167	umask 222
6168	umask
6169expected-stdout:
6170	0222
6171---
6172name: regression-35
6173description:
6174	Tempory files used for here-docs in functions get trashed after
6175	the function is parsed (before it is executed)
6176stdin:
6177	f1() {
6178		cat <<- EOF
6179			F1
6180		EOF
6181		f2() {
6182			cat <<- EOF
6183				F2
6184			EOF
6185		}
6186	}
6187	f1
6188	f2
6189	unset -f f1
6190	f2
6191expected-stdout:
6192	F1
6193	F2
6194	F2
6195---
6196name: regression-36
6197description:
6198	Command substitution breaks reading in while loop
6199	(test from <sjg@void.zen.oz.au>)
6200stdin:
6201	(echo abcdef; echo; echo 123) |
6202	    while read line
6203	    do
6204	      # the following line breaks it
6205	      c=`echo $line | wc -c`
6206	      echo $c
6207	    done
6208expected-stdout:
6209	7
6210	1
6211	4
6212---
6213name: regression-37
6214description:
6215	Machines with broken times() (reported by <sjg@void.zen.oz.au>)
6216	time does not report correct real time
6217stdin:
6218	time sleep 1
6219expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/
6220---
6221name: regression-38
6222description:
6223	set -e doesn't ignore exit codes for if/while/until/&&/||/!.
6224arguments: !-e!
6225stdin:
6226	if false; then echo hi ; fi
6227	false || true
6228	false && true
6229	while false; do echo hi; done
6230	echo ok
6231expected-stdout:
6232	ok
6233---
6234name: regression-39
6235description:
6236	Only posh and oksh(2013-07) say “hi” below; FreeBSD sh,
6237	GNU bash in POSIX mode, dash, ksh93, mksh don’t. All of
6238	them exit 0. The POSIX behaviour is needed by BSD make.
6239stdin:
6240	set -e
6241	echo `false; echo hi` $(<this-file-does-not-exist)
6242	echo $?
6243expected-stdout:
6244
6245	0
6246expected-stderr-pattern: /this-file-does-not-exist/
6247---
6248name: regression-40
6249description:
6250	This used to cause a core dump
6251env-setup: !RANDOM=12!
6252stdin:
6253	echo hi
6254expected-stdout:
6255	hi
6256---
6257name: regression-41
6258description:
6259	foo should be set to bar (should not be empty)
6260stdin:
6261	foo=`
6262	echo bar`
6263	echo "($foo)"
6264expected-stdout:
6265	(bar)
6266---
6267name: regression-42
6268description:
6269	Can't use command line assignments to assign readonly parameters.
6270stdin:
6271	print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6272	    'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6273	    done >env; chmod +x env; PATH=.$PATHSEP$PATH
6274	foo=bar
6275	readonly foo
6276	foo=stuff env | grep '^foo'
6277expected-exit: e != 0
6278expected-stderr-pattern:
6279	/read-only/
6280---
6281name: regression-43
6282description:
6283	Can subshells be prefixed by redirections (historical shells allow
6284	this)
6285stdin:
6286	< /dev/null (sed 's/^/X/')
6287---
6288name: regression-45
6289description:
6290	Parameter assignments with [] recognised correctly
6291stdin:
6292	FOO=*[12]
6293	BAR=abc[
6294	MORE=[abc]
6295	JUNK=a[bc
6296	echo "<$FOO>"
6297	echo "<$BAR>"
6298	echo "<$MORE>"
6299	echo "<$JUNK>"
6300expected-stdout:
6301	<*[12]>
6302	<abc[>
6303	<[abc]>
6304	<a[bc>
6305---
6306name: regression-46
6307description:
6308	Check that alias expansion works in command substitutions and
6309	at the end of file.
6310stdin:
6311	alias x='echo hi'
6312	FOO="`x` "
6313	echo "[$FOO]"
6314	x
6315expected-stdout:
6316	[hi ]
6317	hi
6318---
6319name: regression-47
6320description:
6321	Check that aliases are fully read.
6322stdin:
6323	alias x='echo hi;
6324	echo there'
6325	x
6326	echo done
6327expected-stdout:
6328	hi
6329	there
6330	done
6331---
6332name: regression-48
6333description:
6334	Check that (here doc) temp files are not left behind after an exec.
6335stdin:
6336	mkdir foo || exit 1
6337	TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
6338		x() {
6339			sed 's/^/X /' << E_O_F
6340			hi
6341			there
6342			folks
6343			E_O_F
6344			echo "done ($?)"
6345		}
6346		echo=echo; [ -x /bin/echo ] && echo=/bin/echo
6347		exec $echo subtest-1 hi
6348	EOF
6349	echo subtest-1 foo/*
6350	TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
6351		echo=echo; [ -x /bin/echo ] && echo=/bin/echo
6352		sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi
6353		a
6354		few
6355		lines
6356		E_O_F
6357	EOF
6358	echo subtest-2 foo/*
6359expected-stdout:
6360	subtest-1 hi
6361	subtest-1 foo/*
6362	X a
6363	X few
6364	X lines
6365	subtest-2 hi
6366	subtest-2 foo/*
6367---
6368name: regression-49
6369description:
6370	Check that unset params with attributes are reported by set, those
6371	sans attributes are not.
6372stdin:
6373	unset FOO BAR
6374	echo X$FOO
6375	export BAR
6376	typeset -i BLAH
6377	set | grep FOO
6378	set | grep BAR
6379	set | grep BLAH
6380expected-stdout:
6381	X
6382	BAR
6383	BLAH
6384---
6385name: regression-50
6386description:
6387	Check that aliases do not use continuation prompt after trailing
6388	semi-colon.
6389file-setup: file 644 "envf"
6390	PS1=Y
6391	PS2=X
6392env-setup: !ENV=./envf!
6393need-ctty: yes
6394arguments: !-i!
6395stdin:
6396	alias foo='echo hi ; '
6397	foo
6398	foo echo there
6399expected-stdout:
6400	hi
6401	hi
6402	there
6403expected-stderr: !
6404	YYYY
6405---
6406name: regression-51
6407description:
6408	Check that set allows both +o and -o options on same command line.
6409stdin:
6410	set a b c
6411	set -o noglob +o allexport
6412	echo A: $*, *
6413expected-stdout:
6414	A: a b c, *
6415---
6416name: regression-52
6417description:
6418	Check that globbing works in pipelined commands
6419file-setup: file 644 "envf"
6420	PS1=P
6421file-setup: file 644 "abc"
6422	stuff
6423env-setup: !ENV=./envf!
6424need-ctty: yes
6425arguments: !-i!
6426stdin:
6427	sed 's/^/X /' < ab*
6428	echo mark 1
6429	sed 's/^/X /' < ab* | sed 's/^/Y /'
6430	echo mark 2
6431expected-stdout:
6432	X stuff
6433	mark 1
6434	Y X stuff
6435	mark 2
6436expected-stderr: !
6437	PPPPP
6438---
6439name: regression-53
6440description:
6441	Check that getopts works in functions
6442stdin:
6443	bfunc() {
6444	    echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
6445	    while getopts B oc; do
6446		case $oc in
6447		  (B)
6448		    echo bfunc: B option
6449		    ;;
6450		  (*)
6451		    echo bfunc: odd option "($oc)"
6452		    ;;
6453		esac
6454	    done
6455	    echo bfunc: leave
6456	}
6457
6458	function kfunc {
6459	    echo kfunc: enter "(args: $*; OPTIND=$OPTIND)"
6460	    while getopts K oc; do
6461		case $oc in
6462		  (K)
6463		    echo kfunc: K option
6464		    ;;
6465		  (*)
6466		    echo bfunc: odd option "($oc)"
6467		    ;;
6468		esac
6469	    done
6470	    echo kfunc: leave
6471	}
6472
6473	set -- -f -b -k -l
6474	echo "line 1: OPTIND=$OPTIND"
6475	getopts kbfl optc
6476	echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND"
6477	bfunc -BBB blah
6478	echo "line 3: OPTIND=$OPTIND"
6479	getopts kbfl optc
6480	echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND"
6481	kfunc -KKK blah
6482	echo "line 5: OPTIND=$OPTIND"
6483	getopts kbfl optc
6484	echo "line 6: ret=$?, optc=$optc, OPTIND=$OPTIND"
6485	echo
6486
6487	OPTIND=1
6488	set -- -fbkl
6489	echo "line 10: OPTIND=$OPTIND"
6490	getopts kbfl optc
6491	echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND"
6492	bfunc -BBB blah
6493	echo "line 30: OPTIND=$OPTIND"
6494	getopts kbfl optc
6495	echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND"
6496	kfunc -KKK blah
6497	echo "line 50: OPTIND=$OPTIND"
6498	getopts kbfl optc
6499	echo "line 60: ret=$?, optc=$optc, OPTIND=$OPTIND"
6500expected-stdout:
6501	line 1: OPTIND=1
6502	line 2: ret=0, optc=f, OPTIND=2
6503	bfunc: enter (args: -BBB blah; OPTIND=2)
6504	bfunc: B option
6505	bfunc: B option
6506	bfunc: leave
6507	line 3: OPTIND=2
6508	line 4: ret=0, optc=b, OPTIND=3
6509	kfunc: enter (args: -KKK blah; OPTIND=1)
6510	kfunc: K option
6511	kfunc: K option
6512	kfunc: K option
6513	kfunc: leave
6514	line 5: OPTIND=3
6515	line 6: ret=0, optc=k, OPTIND=4
6516
6517	line 10: OPTIND=1
6518	line 20: ret=0, optc=f, OPTIND=2
6519	bfunc: enter (args: -BBB blah; OPTIND=2)
6520	bfunc: B option
6521	bfunc: B option
6522	bfunc: leave
6523	line 30: OPTIND=2
6524	line 40: ret=1, optc=?, OPTIND=2
6525	kfunc: enter (args: -KKK blah; OPTIND=1)
6526	kfunc: K option
6527	kfunc: K option
6528	kfunc: K option
6529	kfunc: leave
6530	line 50: OPTIND=2
6531	line 60: ret=1, optc=?, OPTIND=2
6532---
6533name: regression-54
6534description:
6535	Check that ; is not required before the then in if (( ... )) then ...
6536stdin:
6537	if (( 1 )) then
6538	    echo ok dparen
6539	fi
6540	if [[ -n 1 ]] then
6541	    echo ok dbrackets
6542	fi
6543expected-stdout:
6544	ok dparen
6545	ok dbrackets
6546---
6547name: regression-55
6548description:
6549	Check ${foo:%bar} is allowed (ksh88 allows it...)
6550stdin:
6551	x=fooXbarXblah
6552	echo 1 ${x%X*}
6553	echo 2 ${x:%X*}
6554	echo 3 ${x%%X*}
6555	echo 4 ${x:%%X*}
6556	echo 5 ${x#*X}
6557	echo 6 ${x:#*X}
6558	echo 7 ${x##*X}
6559	echo 8 ${x:##*X}
6560expected-stdout:
6561	1 fooXbar
6562	2 fooXbar
6563	3 foo
6564	4 foo
6565	5 barXblah
6566	6 barXblah
6567	7 blah
6568	8 blah
6569---
6570name: regression-57
6571description:
6572	Check if typeset output is correct for
6573	uninitialised array elements.
6574stdin:
6575	typeset -i xxx[4]
6576	echo A
6577	typeset -i | grep xxx | sed 's/^/    /'
6578	echo B
6579	typeset | grep xxx | sed 's/^/    /'
6580
6581	xxx[1]=2+5
6582	echo M
6583	typeset -i | grep xxx | sed 's/^/    /'
6584	echo N
6585	typeset | grep xxx | sed 's/^/    /'
6586expected-stdout:
6587	A
6588	    xxx
6589	B
6590	    typeset -i xxx
6591	M
6592	    xxx[1]=7
6593	N
6594	    set -A xxx
6595	    typeset -i xxx[1]
6596---
6597name: regression-58
6598description:
6599	Check if trap exit is ok (exit not mistaken for signal name)
6600stdin:
6601	trap 'echo hi' exit
6602	trap exit 1
6603expected-stdout:
6604	hi
6605---
6606name: regression-59
6607description:
6608	Check if ${#array[*]} is calculated correctly.
6609stdin:
6610	a[12]=hi
6611	a[8]=there
6612	echo ${#a[*]}
6613expected-stdout:
6614	2
6615---
6616name: regression-60
6617description:
6618	Check if default exit status is previous command
6619stdin:
6620	(true; exit)
6621	echo A $?
6622	(false; exit)
6623	echo B $?
6624	( (exit 103) ; exit)
6625	echo C $?
6626expected-stdout:
6627	A 0
6628	B 1
6629	C 103
6630---
6631name: regression-61
6632description:
6633	Check if EXIT trap is executed for sub shells.
6634stdin:
6635	trap 'echo parent exit' EXIT
6636	echo start
6637	(echo A; echo A last)
6638	echo B
6639	(echo C; trap 'echo sub exit' EXIT; echo C last)
6640	echo parent last
6641expected-stdout:
6642	start
6643	A
6644	A last
6645	B
6646	C
6647	C last
6648	sub exit
6649	parent last
6650	parent exit
6651---
6652name: regression-62
6653description:
6654	Check if test -nt/-ot succeeds if second(first) file is missing.
6655stdin:
6656	:>a
6657	test a -nt b && echo nt OK || echo nt BAD
6658	test b -ot a && echo ot OK || echo ot BAD
6659expected-stdout:
6660	nt OK
6661	ot OK
6662---
6663name: regression-63
6664description:
6665	Check if typeset, export, and readonly work
6666stdin:
6667	{
6668		echo FNORD-0
6669		FNORD_A=1
6670		FNORD_B=2
6671		FNORD_C=3
6672		FNORD_D=4
6673		FNORD_E=5
6674		FNORD_F=6
6675		FNORD_G=7
6676		FNORD_H=8
6677		integer FNORD_E FNORD_F FNORD_G FNORD_H
6678		export FNORD_C FNORD_D FNORD_G FNORD_H
6679		readonly FNORD_B FNORD_D FNORD_F FNORD_H
6680		echo FNORD-1
6681		export
6682		echo FNORD-2
6683		export -p
6684		echo FNORD-3
6685		readonly
6686		echo FNORD-4
6687		readonly -p
6688		echo FNORD-5
6689		typeset
6690		echo FNORD-6
6691		typeset -p
6692		echo FNORD-7
6693		typeset -
6694		echo FNORD-8
6695	} | fgrep FNORD
6696	fnord=(42 23)
6697	typeset -p fnord
6698	echo FNORD-9
6699expected-stdout:
6700	FNORD-0
6701	FNORD-1
6702	FNORD_C
6703	FNORD_D
6704	FNORD_G
6705	FNORD_H
6706	FNORD-2
6707	export FNORD_C=3
6708	export FNORD_D=4
6709	export FNORD_G=7
6710	export FNORD_H=8
6711	FNORD-3
6712	FNORD_B
6713	FNORD_D
6714	FNORD_F
6715	FNORD_H
6716	FNORD-4
6717	readonly FNORD_B=2
6718	readonly FNORD_D=4
6719	readonly FNORD_F=6
6720	readonly FNORD_H=8
6721	FNORD-5
6722	typeset FNORD_A
6723	typeset -r FNORD_B
6724	typeset -x FNORD_C
6725	typeset -x -r FNORD_D
6726	typeset -i FNORD_E
6727	typeset -i -r FNORD_F
6728	typeset -i -x FNORD_G
6729	typeset -i -x -r FNORD_H
6730	FNORD-6
6731	typeset FNORD_A=1
6732	typeset -r FNORD_B=2
6733	typeset -x FNORD_C=3
6734	typeset -x -r FNORD_D=4
6735	typeset -i FNORD_E=5
6736	typeset -i -r FNORD_F=6
6737	typeset -i -x FNORD_G=7
6738	typeset -i -x -r FNORD_H=8
6739	FNORD-7
6740	FNORD_A=1
6741	FNORD_B=2
6742	FNORD_C=3
6743	FNORD_D=4
6744	FNORD_E=5
6745	FNORD_F=6
6746	FNORD_G=7
6747	FNORD_H=8
6748	FNORD-8
6749	set -A fnord
6750	typeset fnord[0]=42
6751	typeset fnord[1]=23
6752	FNORD-9
6753---
6754name: regression-64
6755description:
6756	Check that we can redefine functions calling time builtin
6757stdin:
6758	t() {
6759		time >/dev/null
6760	}
6761	t 2>/dev/null
6762	t() {
6763		time
6764	}
6765---
6766name: regression-65
6767description:
6768	check for a regression with sleep builtin and signal mask
6769category: !nojsig
6770time-limit: 5
6771stdin:
6772	sleep 1
6773	echo blub |&
6774	while read -p line; do :; done
6775	echo ok
6776expected-stdout:
6777	ok
6778---
6779name: regression-66
6780description:
6781	Check that quoting is sane
6782category: !nojsig
6783stdin:
6784	ac_space=' '
6785	ac_newline='
6786	'
6787	set | grep ^ac_ |&
6788	set -A lines
6789	while IFS= read -pr line; do
6790		if [[ $line = *space* ]]; then
6791			lines[0]=$line
6792		else
6793			lines[1]=$line
6794		fi
6795	done
6796	for line in "${lines[@]}"; do
6797		print -r -- "$line"
6798	done
6799expected-stdout:
6800	ac_space=' '
6801	ac_newline=$'\n'
6802---
6803name: regression-67
6804description:
6805	Check that we can both break and use source on the same line
6806stdin:
6807	for s in s; do break; done; print -s s
6808---
6809name: regression-68
6810description:
6811	Check that all common arithmetic operators work as expected
6812stdin:
6813	echo 1 $(( a = 5 )) .
6814	echo 2 $(( ++a )) , $(( a++ )) , $(( a )) .
6815	echo 3 $(( --a )) , $(( a-- )) , $(( a )) .
6816	echo 4 $(( a == 5 )) , $(( a == 6 )) .
6817	echo 5 $(( a != 5 )) , $(( a != 6 )) .
6818	echo 6 $(( a *= 3 )) .
6819	echo 7 $(( a /= 5 )) .
6820	echo 8 $(( a %= 2 )) .
6821	echo 9 $(( a += 9 )) .
6822	echo 10 $(( a -= 4 )) .
6823	echo 11 $(( a <<= 1 )) .
6824	echo 12 $(( a >>= 1 )) .
6825	echo 13 $(( a &= 4 )) .
6826	echo 14 $(( a ^= a )) .
6827	echo 15 $(( a |= 5 )) .
6828	echo 16 $(( 5 << 1 )) .
6829	echo 17 $(( 5 >> 1 )) .
6830	echo 18 $(( 5 <= 6 )) , $(( 5 <= 5 )) , $(( 5 <= 4 )) .
6831	echo 19 $(( 5 >= 6 )) , $(( 5 >= 5 )) , $(( 5 >= 4 )) .
6832	echo 20 $(( 5 < 6 )) , $(( 5 < 5 )) , $(( 5 < 4 )) .
6833	echo 21 $(( 5 > 6 )) , $(( 5 > 5 )) , $(( 5 > 4 )) .
6834	echo 22 $(( 0 && 0 )) , $(( 0 && 1 )) , $(( 1 && 0 )) , $(( 1 && 1 )) .
6835	echo 23 $(( 0 || 0 )) , $(( 0 || 1 )) , $(( 1 || 0 )) , $(( 1 || 1 )) .
6836	echo 24 $(( 5 * 3 )) .
6837	echo 25 $(( 7 / 2 )) .
6838	echo 26 $(( 5 % 5 )) , $(( 5 % 4 )) , $(( 5 % 1 )) , $(( 5 % -1 )) , $(( 5 % -2 )) .
6839	echo 27 $(( 5 + 2 )) , $(( 5 + 0 )) , $(( 5 + -2 )) .
6840	echo 28 $(( 5 - 2 )) , $(( 5 - 0 )) , $(( 5 - -2 )) .
6841	echo 29 $(( 6 & 4 )) , $(( 6 & 8 )) .
6842	echo 30 $(( 4 ^ 2 )) , $(( 4 ^ 4 )) .
6843	echo 31 $(( 4 | 2 )) , $(( 4 | 4 )) , $(( 4 | 0 )) .
6844	echo 32 $(( 0 ? 1 : 2 )) , $(( 3 ? 4 : 5 )) .
6845	echo 33 $(( 5 , 2 , 3 )) .
6846	echo 34 $(( ~0 )) , $(( ~1 )) , $(( ~~1 )) , $(( ~~2 )) .
6847	echo 35 $(( !0 )) , $(( !1 )) , $(( !!1 )) , $(( !!2 )) .
6848	echo 36 $(( (5) )) .
6849expected-stdout:
6850	1 5 .
6851	2 6 , 6 , 7 .
6852	3 6 , 6 , 5 .
6853	4 1 , 0 .
6854	5 0 , 1 .
6855	6 15 .
6856	7 3 .
6857	8 1 .
6858	9 10 .
6859	10 6 .
6860	11 12 .
6861	12 6 .
6862	13 4 .
6863	14 0 .
6864	15 5 .
6865	16 10 .
6866	17 2 .
6867	18 1 , 1 , 0 .
6868	19 0 , 1 , 1 .
6869	20 1 , 0 , 0 .
6870	21 0 , 0 , 1 .
6871	22 0 , 0 , 0 , 1 .
6872	23 0 , 1 , 1 , 1 .
6873	24 15 .
6874	25 3 .
6875	26 0 , 1 , 0 , 0 , 1 .
6876	27 7 , 5 , 3 .
6877	28 3 , 5 , 7 .
6878	29 4 , 0 .
6879	30 6 , 0 .
6880	31 6 , 4 , 4 .
6881	32 2 , 4 .
6882	33 3 .
6883	34 -1 , -2 , 1 , 2 .
6884	35 1 , 0 , 1 , 1 .
6885	36 5 .
6886---
6887name: regression-69
6888description:
6889	Check that all non-lksh arithmetic operators work as expected
6890category: shell:legacy-no
6891stdin:
6892	a=5 b=0x80000005
6893	echo 1 $(( a ^<= 1 )) , $(( b ^<= 1 )) .
6894	echo 2 $(( a ^>= 2 )) , $(( b ^>= 2 )) .
6895	echo 3 $(( 5 ^< 1 )) .
6896	echo 4 $(( 5 ^> 1 )) .
6897expected-stdout:
6898	1 10 , 11 .
6899	2 -2147483646 , -1073741822 .
6900	3 10 .
6901	4 -2147483646 .
6902---
6903name: export-1
6904description:
6905	Check allexport works, basic
6906stdin:
6907	qa=1
6908	set -A qb 2 3
6909	set -a
6910	qc=4
6911	set -A qd 5 6
6912	export -p | grep '^export q'
6913expected-stdout:
6914	export qc=4
6915	export qd[0]=5
6916	export qd[1]=6
6917---
6918name: readonly-0
6919description:
6920	Ensure readonly is honoured for assignments and unset
6921stdin:
6922	"$__progname" -c 'u=x; echo $? $u .' || echo aborted, $?
6923	echo =
6924	"$__progname" -c 'readonly u; u=x; echo $? $u .' || echo aborted, $?
6925	echo =
6926	"$__progname" -c 'u=x; readonly u; unset u; echo $? $u .' || echo aborted, $?
6927expected-stdout:
6928	0 x .
6929	=
6930	aborted, 2
6931	=
6932	1 x .
6933expected-stderr-pattern:
6934	/read-only/
6935---
6936name: readonly-1
6937description:
6938	http://austingroupbugs.net/view.php?id=367 for export
6939stdin:
6940	"$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $?
6941expected-stdout:
6942	aborted, 2
6943expected-stderr-pattern:
6944	/read-only/
6945---
6946name: readonly-2a
6947description:
6948	Check that getopts works as intended, for readonly-2b to be valid
6949stdin:
6950	"$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $?
6951expected-stdout:
6952	0 a .
6953	1 ? .
6954---
6955name: readonly-2b
6956description:
6957	http://austingroupbugs.net/view.php?id=367 for getopts
6958stdin:
6959	"$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $?
6960expected-stdout:
6961	2 .
6962expected-stderr-pattern:
6963	/read-only/
6964---
6965name: readonly-3
6966description:
6967	http://austingroupbugs.net/view.php?id=367 for read
6968stdin:
6969	echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $?
6970	echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $?
6971expected-stdout:
6972	0 x .
6973	2 .
6974expected-stderr-pattern:
6975	/read-only/
6976---
6977name: readonly-4
6978description:
6979	Do not permit bypassing readonly for first array item
6980stdin:
6981	set -A arr -- foo bar
6982	readonly arr
6983	arr=baz
6984	print -r -- "${arr[@]}"
6985expected-exit: e != 0
6986expected-stderr-pattern:
6987	/read[ -]?only/
6988---
6989name: readonly-5
6990description:
6991	Ensure readonly is idempotent
6992stdin:
6993	readonly x=1
6994	readonly x
6995---
6996name: syntax-1
6997description:
6998	Check that lone ampersand is a syntax error
6999stdin:
7000	 &
7001expected-exit: e != 0
7002expected-stderr-pattern:
7003	/syntax error/
7004---
7005name: xxx-quoted-newline-1
7006description:
7007	Check that \<newline> works inside of ${}
7008stdin:
7009	abc=2
7010	echo ${ab\
7011	c}
7012expected-stdout:
7013	2
7014---
7015name: xxx-quoted-newline-2
7016description:
7017	Check that \<newline> works at the start of a here document
7018stdin:
7019	cat << EO\
7020	F
7021	hi
7022	EOF
7023expected-stdout:
7024	hi
7025---
7026name: xxx-quoted-newline-3
7027description:
7028	Check that \<newline> works at the end of a here document
7029stdin:
7030	cat << EOF
7031	hi
7032	EO\
7033	F
7034expected-stdout:
7035	hi
7036---
7037name: xxx-multi-assignment-cmd
7038description:
7039	Check that assignments in a command affect subsequent assignments
7040	in the same command
7041stdin:
7042	FOO=abc
7043	FOO=123 BAR=$FOO
7044	echo $BAR
7045expected-stdout:
7046	123
7047---
7048name: xxx-multi-assignment-posix-cmd
7049description:
7050	Check that the behaviour for multiple assignments with a
7051	command name matches POSIX. See:
7052	http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
7053stdin:
7054	X=a Y=b; X=$Y Y=$X "$__progname" -c 'echo 1 $X $Y .'; echo 2 $X $Y .
7055	unset X Y Z
7056	X=a Y=${X=b} Z=$X "$__progname" -c 'echo 3 $Z .'
7057	unset X Y Z
7058	X=a Y=${X=b} Z=$X; echo 4 $Z .
7059expected-stdout:
7060	1 b a .
7061	2 a b .
7062	3 b .
7063	4 a .
7064---
7065name: xxx-multi-assignment-posix-nocmd
7066description:
7067	Check that the behaviour for multiple assignments with no
7068	command name matches POSIX (Debian #334182). See:
7069	http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
7070stdin:
7071	X=a Y=b; X=$Y Y=$X; echo 1 $X $Y .
7072expected-stdout:
7073	1 b b .
7074---
7075name: xxx-multi-assignment-posix-subassign
7076description:
7077	Check that the behaviour for multiple assignments matches POSIX:
7078	- The assignment words shall be expanded in the current execution
7079	  environment.
7080	- The assignments happen in the temporary execution environment.
7081stdin:
7082	unset X Y Z
7083	Z=a Y=${X:=b} sh -c 'echo +$X+ +$Y+ +$Z+'
7084	echo /$X/
7085	# Now for the special case:
7086	unset X Y Z
7087	X= Y=${X:=b} sh -c 'echo +$X+ +$Y+'
7088	echo /$X/
7089expected-stdout:
7090	++ +b+ +a+
7091	/b/
7092	++ +b+
7093	/b/
7094---
7095name: xxx-exec-environment-1
7096description:
7097	Check to see if exec sets it's environment correctly
7098stdin:
7099	print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
7100	    'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
7101	    done >env; chmod +x env; PATH=.$PATHSEP$PATH
7102	FOO=bar exec env
7103expected-stdout-pattern:
7104	/(^|.*\n)FOO=bar\n/
7105---
7106name: xxx-exec-environment-2
7107description:
7108	Check to make sure exec doesn't change environment if a program
7109	isn't exec-ed
7110stdin:
7111	print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
7112	    'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
7113	    done >env; chmod +x env; PATH=.$PATHSEP$PATH
7114	env >bar1
7115	FOO=bar exec; env >bar2
7116	cmp -s bar1 bar2
7117---
7118name: exec-function-environment-1
7119description:
7120	Check assignments in function calls and whether they affect
7121	the current execution environment (ksh93, SUSv4)
7122stdin:
7123	f() { a=2; }; g() { b=3; echo y$c-; }; a=1 f; b=2; c=1 g
7124	echo x$a-$b- z$c-
7125expected-stdout:
7126	y1-
7127	x2-3- z1-
7128---
7129name: exec-modern-korn-shell
7130description:
7131	Check that exec can execute any command that makes it
7132	through syntax and parser
7133stdin:
7134	print '#!'"$__progname"'\necho tf' >lq
7135	chmod +x lq
7136	PATH=$PWD
7137	exec 2>&1
7138	foo() { print two; }
7139	print =1
7140	(exec print one)
7141	print =2
7142	(exec foo)
7143	print =3
7144	(exec ls)
7145	print =4
7146	(exec lq)
7147expected-stdout-pattern:
7148	/=1\none\n=2\ntwo\n=3\n.*: ls: inaccessible or not found\n=4\ntf\n/
7149---
7150name: exec-ksh88
7151description:
7152	Check that exec only executes after a PATH search
7153arguments: !-o!posix!
7154stdin:
7155	print '#!'"$__progname"'\necho tf' >lq
7156	chmod +x lq
7157	PATH=$PWD
7158	exec 2>&1
7159	foo() { print two; }
7160	print =1
7161	(exec print one)
7162	print =2
7163	(exec foo)
7164	print =3
7165	(exec ls)
7166	print =4
7167	(exec lq)
7168expected-stdout-pattern:
7169	/=1\n.*: print: inaccessible or not found\n=2\n.*: foo: inaccessible or not found\n=3\n.*: ls: inaccessible or not found\n=4\ntf\n/
7170---
7171name: xxx-what-do-you-call-this-1
7172stdin:
7173	echo "${foo:-"a"}*"
7174expected-stdout:
7175	a*
7176---
7177name: xxx-prefix-strip-1
7178stdin:
7179	foo='a cdef'
7180	echo ${foo#a c}
7181expected-stdout:
7182	def
7183---
7184name: xxx-prefix-strip-2
7185stdin:
7186	set a c
7187	x='a cdef'
7188	echo ${x#$*}
7189expected-stdout:
7190	def
7191---
7192name: xxx-variable-syntax-1
7193stdin:
7194	echo ${:}
7195expected-stderr-pattern:
7196	/bad substitution/
7197expected-exit: 1
7198---
7199name: xxx-variable-syntax-2
7200stdin:
7201	set 0
7202	echo ${*:0}
7203expected-stderr-pattern:
7204	/bad substitution/
7205expected-exit: 1
7206---
7207name: xxx-variable-syntax-3
7208stdin:
7209	set -A foo 0
7210	echo ${foo[*]:0}
7211expected-stderr-pattern:
7212	/bad substitution/
7213expected-exit: 1
7214---
7215name: xxx-variable-syntax-4
7216description:
7217	Not all kinds of trims are currently impossible, check those who do
7218stdin:
7219	foo() {
7220		echo "<$*> X${*:+ }X"
7221	}
7222	foo a b
7223	foo "" c
7224	foo ""
7225	foo "" ""
7226	IFS=:
7227	foo a b
7228	foo "" c
7229	foo ""
7230	foo "" ""
7231	IFS=
7232	foo a b
7233	foo "" c
7234	foo ""
7235	foo "" ""
7236expected-stdout:
7237	<a b> X X
7238	< c> X X
7239	<> XX
7240	< > X X
7241	<a:b> X X
7242	<:c> X X
7243	<> XX
7244	<:> X X
7245	<ab> X X
7246	<c> X X
7247	<> XX
7248	<> XX
7249---
7250name: xxx-substitution-eval-order
7251description:
7252	Check order of evaluation of expressions
7253stdin:
7254	i=1 x= y=
7255	set -A A abc def GHI j G k
7256	echo ${A[x=(i+=1)]#${A[y=(i+=2)]}}
7257	echo $x $y
7258expected-stdout:
7259	HI
7260	2 4
7261---
7262name: xxx-substitution-eval-order-2
7263description:
7264	Check some corner cases
7265stdin:
7266	unset var
7267	i=42
7268	: ${var+${q[i=777]}} required to be lazy by POSIX
7269	echo 1=$i
7270	var=meow
7271	i=42
7272	: ${var+${q[i=777]}} eval since var is now set
7273	echo 2=$i
7274	unset var
7275	i=42
7276	: ${var#${q[i=777]}} pattern is needed even if var is empty
7277	echo 3=$i
7278	var=meow
7279	i=42
7280	: ${var#${q[i=777]}}
7281	echo 4=$i
7282expected-stdout:
7283	1=42
7284	2=777
7285	3=777
7286	4=777
7287---
7288name: xxx-set-option-1
7289description:
7290	Check option parsing in set
7291stdin:
7292	set -vsA foo -- A 1 3 2
7293	echo ${foo[*]}
7294expected-stderr:
7295	echo ${foo[*]}
7296expected-stdout:
7297	1 2 3 A
7298---
7299name: xxx-exec-1
7300description:
7301	Check that exec exits for built-ins
7302need-ctty: yes
7303arguments: !-i!
7304stdin:
7305	exec echo hi
7306	echo still herre
7307expected-stdout:
7308	hi
7309expected-stderr-pattern: /.*/
7310---
7311name: xxx-while-1
7312description:
7313	Check the return value of while loops
7314	XXX need to do same for for/select/until loops
7315stdin:
7316	i=x
7317	while [ $i != xxx ] ; do
7318	    i=x$i
7319	    if [ $i = xxx ] ; then
7320		false
7321		continue
7322	    fi
7323	done
7324	echo loop1=$?
7325
7326	i=x
7327	while [ $i != xxx ] ; do
7328	    i=x$i
7329	    if [ $i = xxx ] ; then
7330		false
7331		break
7332	    fi
7333	done
7334	echo loop2=$?
7335
7336	i=x
7337	while [ $i != xxx ] ; do
7338	    i=x$i
7339	    false
7340	done
7341	echo loop3=$?
7342expected-stdout:
7343	loop1=0
7344	loop2=0
7345	loop3=1
7346---
7347name: xxx-status-1
7348description:
7349	Check that blank lines don't clear $?
7350need-ctty: yes
7351arguments: !-i!
7352stdin:
7353	(exit 1)
7354	echo $?
7355	(exit 1)
7356
7357	echo $?
7358	true
7359expected-stdout:
7360	1
7361	1
7362expected-stderr-pattern: /.*/
7363---
7364name: xxx-status-2
7365description:
7366	Check that $? is preserved in subshells, includes, traps.
7367stdin:
7368	(exit 1)
7369
7370	echo blank: $?
7371
7372	(exit 2)
7373	(echo subshell: $?)
7374
7375	echo 'echo include: $?' > foo
7376	(exit 3)
7377	. ./foo
7378
7379	trap 'echo trap: $?' ERR
7380	(exit 4)
7381	echo exit: $?
7382expected-stdout:
7383	blank: 1
7384	subshell: 2
7385	include: 3
7386	trap: 4
7387	exit: 4
7388---
7389name: xxx-stat-1
7390description:
7391	Check that tests on files are consistent
7392stdin:
7393	mkdir a
7394	echo x >a/b
7395	test -e a/b; echo 1e $? .
7396	test -f a/b; echo 1f $? .
7397	chmod 0 a
7398	test -e a/b; echo 2e $? .
7399	test -f a/b; echo 2f $? .
7400	chmod 700 a
7401	test -e a/b; echo 3e $? .
7402	test -f a/b; echo 3f $? .
7403expected-stdout:
7404	1e 0 .
7405	1f 0 .
7406	2e 1 .
7407	2f 1 .
7408	3e 0 .
7409	3f 0 .
7410---
7411name: xxx-clean-chars-1
7412description:
7413	Check MAGIC character is stuffed correctly
7414stdin:
7415	echo `echo [�`
7416expected-stdout:
7417	[�
7418---
7419name: xxx-param-subst-qmark-1
7420description:
7421	Check suppresion of error message with null string.  According to
7422	POSIX, it shouldn't print the error as 'word' isn't ommitted.
7423	ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error.
7424stdin:
7425	unset foo
7426	x=
7427	echo x${foo?$x}
7428expected-exit: 1
7429expected-stderr-pattern: !/not set/
7430---
7431name: xxx-param-subst-qmark-namespec
7432description:
7433	Check special names are output correctly
7434stdin:
7435	doit() {
7436		"$__progname" -c "$@" >o1 2>o2
7437		rv=$?
7438		echo RETVAL: $rv
7439		sed -e "s^${__progname%.exe}\.*e*x*e*: PROG: " -e 's/^/STDOUT: /g' <o1
7440		sed -e "s^${__progname%.exe}\.*e*x*e*: PROG: " -e 's/^/STDERR: /g' <o2
7441	}
7442	doit 'echo ${1x}'
7443	doit 'echo "${1x}"'
7444	doit 'echo ${1?}'
7445	doit 'echo ${19?}'
7446	doit 'echo ${!:?}'
7447	doit -u 'echo ${*:?}' foo ""
7448expected-stdout:
7449	RETVAL: 1
7450	STDERR: PROG: ${1x}: bad substitution
7451	RETVAL: 1
7452	STDERR: PROG: ${1x}: bad substitution
7453	RETVAL: 1
7454	STDERR: PROG: 1: parameter null or not set
7455	RETVAL: 1
7456	STDERR: PROG: 19: parameter null or not set
7457	RETVAL: 1
7458	STDERR: PROG: !: parameter null or not set
7459	RETVAL: 1
7460	STDERR: foo: ${*:?}: bad substitution
7461---
7462name: xxx-param-_-1
7463# fails due to weirdness of execv stuff
7464category: !os:uwin-nt
7465description:
7466	Check c flag is set.
7467arguments: !-c!echo "[$-]"!
7468expected-stdout-pattern: /^\[.*c.*\]$/
7469---
7470name: tilde-expand-1
7471description:
7472	Check tilde expansion after equal signs
7473env-setup: !HOME=/sweet!
7474stdin:
7475	echo ${A=a=}~ b=~ c=d~ ~
7476	export e=~ f=d~
7477	command command export g=~ h=d~
7478	echo ". $e . $f ."
7479	echo ". $g . $h ."
7480	set -o posix
7481	unset A e f g h
7482	echo ${A=a=}~ b=~ c=d~ ~
7483	export e=~ f=d~
7484	command command export g=~ h=d~
7485	echo ". $e . $f ."
7486	echo ". $g . $h ."
7487expected-stdout:
7488	a=/sweet b=/sweet c=d~ /sweet
7489	. /sweet . d~ .
7490	. /sweet . d~ .
7491	a=~ b=~ c=d~ /sweet
7492	. /sweet . d~ .
7493	. /sweet . d~ .
7494---
7495name: tilde-expand-2
7496description:
7497	Check tilde expansion works
7498env-setup: !HOME=/sweet!
7499stdin:
7500	:>'c=a'
7501	typeset c=[ab]
7502	:>'d=a'
7503	x=typeset; $x d=[ab]
7504	echo "<$c>" "<$d>"
7505	wd=$PWD
7506	cd /
7507	plus=$(print -r -- ~+)
7508	minus=$(print -r -- ~-)
7509	nix=$(print -r -- ~)
7510	[[ $plus = / ]]; echo one $? .
7511	[[ $minus = "$wd" ]]; echo two $? .
7512	[[ $nix = /sweet ]]; echo nix $? .
7513expected-stdout:
7514	<[ab]> <a>
7515	one 0 .
7516	two 0 .
7517	nix 0 .
7518---
7519name: tilde-expand-3
7520description:
7521	Check mostly Austin 351 stuff
7522stdin:
7523	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
7524	set "1 b=2" "3 d=4"
7525	export a=$1 \c=$2
7526	showargs 1 "$a" "$b" "$c" "$d"
7527	unset a b c d
7528	HOME=/tmp
7529	export \a=~ b=~
7530	command export c=~
7531	builtin export d=~
7532	\\builtin export e=~
7533	showargs 2 "$a" "$b" "$c" "$d" "$e" ksh
7534	unset a b c d e
7535	set -o posix
7536	export \a=~ b=~
7537	command export c=~
7538	builtin export d=~
7539	\\builtin export e=~
7540	showargs 3 "$a" "$b" "$c" "$d" "$e" posix
7541	unset a b c d e
7542	set +o posix
7543	export a=$1
7544	showargs 4 "$a" "$b" ksh
7545	unset a b
7546	showargs 5 a=$1 ksh
7547	export \a=$1
7548	showargs 6 "$a" "$b" ksh
7549	unset a b
7550	set -o posix
7551	export a=$1
7552	showargs 7 "$a" "$b" posix
7553	unset a b
7554	showargs 8 a=$1 posix
7555	export \a=$1
7556	showargs 9 "$a" "$b" posix
7557	unset a b
7558	set +o posix
7559	command echo 10 ksh a=~
7560	command command export a=~
7561	showargs 11 "$a"
7562	unset a
7563	set -o posix
7564	command echo 12 posix a=~
7565	command command export a=~
7566	showargs 13 "$a"
7567	unset a
7568	# unspecified whether /tmp or ~
7569	var=export; command $var a=~
7570	showargs 14 "$a"
7571	echo 'echo "<$foo>"' >bar
7572	"$__progname" bar
7573	var=foo
7574	export $var=1
7575	"$__progname" bar
7576	export $var=~
7577	"$__progname" bar
7578	# unspecified
7579	command -- export a=~
7580	showargs 18 "$a"
7581	set -A bla
7582	typeset bla[1]=~:~
7583	global gbl=~ g2=$1
7584	local lcl=~ l2=$1
7585	readonly ro=~ r2=$1
7586	showargs 19 "${bla[1]}" a=~ "$gbl" "$lcl" "$ro" "$g2" "$l2" "$r2"
7587	set +o posix
7588	echo "20 some arbitrary stuff "=~
7589	set -o posix
7590	echo "21 some arbitrary stuff "=~
7591expected-stdout:
7592	<1> <1 b=2> <> <3> <4> .
7593	<2> </tmp> </tmp> </tmp> </tmp> </tmp> <ksh> .
7594	<3> <~> </tmp> </tmp> <~> </tmp> <posix> .
7595	<4> <1 b=2> <> <ksh> .
7596	<5> <a=1> <b=2> <ksh> .
7597	<6> <1> <2> <ksh> .
7598	<7> <1 b=2> <> <posix> .
7599	<8> <a=1> <b=2> <posix> .
7600	<9> <1> <2> <posix> .
7601	10 ksh a=/tmp
7602	<11> </tmp> .
7603	12 posix a=~
7604	<13> </tmp> .
7605	<14> <~> .
7606	<>
7607	<1>
7608	<~>
7609	<18> <~> .
7610	<19> </tmp:/tmp> <a=~> </tmp> </tmp> </tmp> <1 b=2> <1 b=2> <1 b=2> .
7611	20 some arbitrary stuff =/tmp
7612	21 some arbitrary stuff =~
7613---
7614name: exit-err-1
7615description:
7616	Check some "exit on error" conditions
7617stdin:
7618	print '#!'"$__progname"'\nexec "$1"' >env
7619	print '#!'"$__progname"'\nexit 1' >false
7620	chmod +x env false
7621	PATH=.$PATHSEP$PATH
7622	set -ex
7623	env false && echo something
7624	echo END
7625expected-stdout:
7626	END
7627expected-stderr:
7628	+ env false
7629	+ echo END
7630---
7631name: exit-err-2
7632description:
7633	Check some "exit on error" edge conditions (POSIXly)
7634stdin:
7635	print '#!'"$__progname"'\nexec "$1"' >env
7636	print '#!'"$__progname"'\nexit 1' >false
7637	print '#!'"$__progname"'\nexit 0' >true
7638	chmod +x env false
7639	PATH=.$PATHSEP$PATH
7640	set -ex
7641	if env true; then
7642		env false && echo something
7643	fi
7644	echo END
7645expected-stdout:
7646	END
7647expected-stderr:
7648	+ env true
7649	+ env false
7650	+ echo END
7651---
7652name: exit-err-3
7653description:
7654	pdksh regression which AT&T ksh does right
7655	TFM says: [set] -e | errexit
7656		Exit (after executing the ERR trap) ...
7657stdin:
7658	trap 'echo EXIT' EXIT
7659	trap 'echo ERR' ERR
7660	set -e
7661	cd /XXXXX 2>/dev/null
7662	echo DONE
7663	exit 0
7664expected-stdout:
7665	ERR
7666	EXIT
7667expected-exit: e != 0
7668---
7669name: exit-err-4
7670description:
7671	"set -e" test suite (POSIX)
7672stdin:
7673	set -e
7674	echo pre
7675	if true ; then
7676		false && echo foo
7677	fi
7678	echo bar
7679expected-stdout:
7680	pre
7681	bar
7682---
7683name: exit-err-5
7684description:
7685	"set -e" test suite (POSIX)
7686stdin:
7687	set -e
7688	foo() {
7689		while [ "$1" ]; do
7690			for E in $x; do
7691				[ "$1" = "$E" ] && { shift ; continue 2 ; }
7692			done
7693			x="$x $1"
7694			shift
7695		done
7696		echo $x
7697	}
7698	echo pre
7699	foo a b b c
7700	echo post
7701expected-stdout:
7702	pre
7703	a b c
7704	post
7705---
7706name: exit-err-6
7707description:
7708	"set -e" test suite (BSD make)
7709category: os:mirbsd
7710stdin:
7711	mkdir zd zd/a zd/b
7712	print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile
7713	print 'all:\n\t@echo zwei\n' >zd/b/Makefile
7714	wd=$(pwd)
7715	set -e
7716	for entry in a b; do (  set -e;  if [[ -d $wd/zd/$entry.i386 ]]; then  _newdir_="$entry.i386";  else  _newdir_="$entry";  fi;  if [[ -z $_THISDIR_ ]]; then  _nextdir_="$_newdir_";  else  _nextdir_="$_THISDIR_/$_newdir_";  fi;  _makefile_spec_=;  [[ ! -f $wd/zd/$_newdir_/Makefile.bsd-wrapper ]]  || _makefile_spec_="-f Makefile.bsd-wrapper";  subskipdir=;  for skipdir in ; do  subentry=${skipdir#$entry};  if [[ $subentry != $skipdir ]]; then  if [[ -z $subentry ]]; then  echo "($_nextdir_ skipped)";  break;  fi;  subskipdir="$subskipdir ${subentry#/}";  fi;  done;  if [[ -z $skipdir || -n $subentry ]]; then  echo "===> $_nextdir_";  cd $wd/zd/$_newdir_;  make SKIPDIR="$subskipdir" $_makefile_spec_  _THISDIR_="$_nextdir_"   all;  fi;  ) done 2>&1 | sed "s!$wd!WD!g"
7717expected-stdout:
7718	===> a
7719	eins
7720	*** Error code 42
7721
7722	Stop in WD/zd/a (line 2 of Makefile).
7723---
7724name: exit-err-7
7725description:
7726	"set -e" regression (LP#1104543)
7727stdin:
7728	set -e
7729	bla() {
7730		[ -x $PWD/nonexistant ] && $PWD/nonexistant
7731	}
7732	echo x
7733	bla
7734	echo y$?
7735expected-stdout:
7736	x
7737expected-exit: 1
7738---
7739name: exit-err-8
7740description:
7741	"set -e" regression (Debian #700526)
7742stdin:
7743	set -e
7744	_db_cmd() { return $1; }
7745	db_input() { _db_cmd 30; }
7746	db_go() { _db_cmd 0; }
7747	db_input || :
7748	db_go
7749	exit 0
7750---
7751name: exit-err-9
7752description:
7753	"set -e" versus bang pipelines
7754stdin:
7755	set -e
7756	! false | false
7757	echo 1 ok
7758	! false && false
7759	echo 2 wrong
7760expected-stdout:
7761	1 ok
7762expected-exit: 1
7763---
7764name: exit-enoent-1
7765description:
7766	SUSv4 says that the shell should exit with 126/127 in some situations
7767stdin:
7768	i=0
7769	(echo; echo :) >x
7770	"$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7771	"$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7772	echo exit 42 >x
7773	"$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7774	"$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7775	rm -f x
7776	"$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7777	"$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7778expected-stdout:
7779	0 0 .
7780	1 126 .
7781	2 42 .
7782	3 126 .
7783	4 127 .
7784	5 127 .
7785---
7786name: exit-eval-1
7787description:
7788	Check eval vs substitution exit codes (ksh93 alike)
7789stdin:
7790	(exit 12)
7791	eval $(false)
7792	echo A $?
7793	(exit 12)
7794	eval ' $(false)'
7795	echo B $?
7796	(exit 12)
7797	eval " $(false)"
7798	echo C $?
7799	(exit 12)
7800	eval "eval $(false)"
7801	echo D $?
7802	(exit 12)
7803	eval 'eval '"$(false)"
7804	echo E $?
7805	IFS="$IFS:"
7806	(exit 12)
7807	eval $(echo :; false)
7808	echo F $?
7809	echo -n "G "
7810	(exit 12)
7811	eval 'echo $?'
7812	echo H $?
7813expected-stdout:
7814	A 0
7815	B 1
7816	C 0
7817	D 0
7818	E 0
7819	F 0
7820	G 12
7821	H 0
7822---
7823name: exit-trap-1
7824description:
7825	Check that "exit" with no arguments behaves SUSv4 conformant.
7826stdin:
7827	trap 'echo hi; exit' EXIT
7828	exit 9
7829expected-stdout:
7830	hi
7831expected-exit: 9
7832---
7833name: exit-trap-2
7834description:
7835	Check that ERR and EXIT traps are run just like ksh93 does.
7836	GNU bash does not run ERtrap in ±e eval-undef but runs it
7837	twice (bug?) in +e eval-false, so does ksh93 (bug?), which
7838	also has a bug to continue execution (echoing "and out" and
7839	returning 0) in +e eval-undef.
7840file-setup: file 644 "x"
7841	v=; unset v
7842	trap 'echo EXtrap' EXIT
7843	trap 'echo ERtrap' ERR
7844	set $1
7845	echo "and run $2"
7846	eval $2
7847	echo and out
7848file-setup: file 644 "xt"
7849	v=; unset v
7850	trap 'echo EXtrap' EXIT
7851	trap 'echo ERtrap' ERR
7852	set $1
7853	echo 'and run true'
7854	true
7855	echo and out
7856file-setup: file 644 "xf"
7857	v=; unset v
7858	trap 'echo EXtrap' EXIT
7859	trap 'echo ERtrap' ERR
7860	set $1
7861	echo 'and run false'
7862	false
7863	echo and out
7864file-setup: file 644 "xu"
7865	v=; unset v
7866	trap 'echo EXtrap' EXIT
7867	trap 'echo ERtrap' ERR
7868	set $1
7869	echo 'and run ${v?}'
7870	${v?}
7871	echo and out
7872stdin:
7873	runtest() {
7874		rm -f rc
7875		(
7876			"$__progname" "$@"
7877			echo $? >rc
7878		) 2>&1 | sed \
7879		    -e 's/parameter not set/parameter null or not set/' \
7880		    -e 's/[[]6]//' -e 's/: eval: line 1//' -e 's/: line 6//' \
7881		    -e "s^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]PROG"
7882	}
7883	xe=-e
7884	echo : $xe
7885	runtest x $xe true
7886	echo = eval-true $(<rc) .
7887	runtest x $xe false
7888	echo = eval-false $(<rc) .
7889	runtest x $xe '${v?}'
7890	echo = eval-undef $(<rc) .
7891	runtest xt $xe
7892	echo = noeval-true $(<rc) .
7893	runtest xf $xe
7894	echo = noeval-false $(<rc) .
7895	runtest xu $xe
7896	echo = noeval-undef $(<rc) .
7897	xe=+e
7898	echo : $xe
7899	runtest x $xe true
7900	echo = eval-true $(<rc) .
7901	runtest x $xe false
7902	echo = eval-false $(<rc) .
7903	runtest x $xe '${v?}'
7904	echo = eval-undef $(<rc) .
7905	runtest xt $xe
7906	echo = noeval-true $(<rc) .
7907	runtest xf $xe
7908	echo = noeval-false $(<rc) .
7909	runtest xu $xe
7910	echo = noeval-undef $(<rc) .
7911expected-stdout:
7912	: -e
7913	and run true
7914	and out
7915	EXtrap
7916	= eval-true 0 .
7917	and run false
7918	ERtrap
7919	EXtrap
7920	= eval-false 1 .
7921	and run ${v?}
7922	x: v: parameter null or not set
7923	ERtrap
7924	EXtrap
7925	= eval-undef 1 .
7926	and run true
7927	and out
7928	EXtrap
7929	= noeval-true 0 .
7930	and run false
7931	ERtrap
7932	EXtrap
7933	= noeval-false 1 .
7934	and run ${v?}
7935	xu: v: parameter null or not set
7936	EXtrap
7937	= noeval-undef 1 .
7938	: +e
7939	and run true
7940	and out
7941	EXtrap
7942	= eval-true 0 .
7943	and run false
7944	ERtrap
7945	and out
7946	EXtrap
7947	= eval-false 0 .
7948	and run ${v?}
7949	x: v: parameter null or not set
7950	ERtrap
7951	EXtrap
7952	= eval-undef 1 .
7953	and run true
7954	and out
7955	EXtrap
7956	= noeval-true 0 .
7957	and run false
7958	ERtrap
7959	and out
7960	EXtrap
7961	= noeval-false 0 .
7962	and run ${v?}
7963	xu: v: parameter null or not set
7964	EXtrap
7965	= noeval-undef 1 .
7966---
7967name: exit-trap-3
7968description:
7969	Check that the EXIT trap is run in many places, Debian #910276
7970stdin:
7971	fkt() {
7972		trap -- "echo $1 >&2" EXIT
7973	}
7974	fkt shell_exit
7975	$(fkt fn_exit)
7976	$(trap -- "echo comsub_exit >&2" EXIT)
7977	(trap -- "echo subshell_exit >&2" EXIT)
7978expected-stderr:
7979	fn_exit
7980	comsub_exit
7981	subshell_exit
7982	shell_exit
7983---
7984name: exit-trap-interactive
7985description:
7986	Check that interactive shell doesn't exit via EXIT trap on syntax error
7987arguments: !-i!
7988stdin:
7989	trap -- EXIT
7990	echo Syntax error <
7991	echo 'After error 1'
7992	trap 'echo Exit trap' EXIT
7993	echo Syntax error <
7994	echo 'After error 2'
7995	trap 'echo Exit trap' EXIT
7996	exit
7997	echo 'After exit'
7998expected-stdout:
7999	After error 1
8000	After error 2
8001	Exit trap
8002expected-stderr-pattern:
8003	/syntax error: unexpected 'newline'/
8004---
8005name: test-stlt-1
8006description:
8007	Check that test also can handle string1 < string2 etc.
8008stdin:
8009	test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
8010	test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
8011	test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein
8012	test 2005/08/21 \> 2005/10/08 && echo ja || echo nein
8013expected-stdout:
8014	nein
8015	ja
8016	ja
8017	nein
8018expected-stderr-pattern: !/unexpected op/
8019---
8020name: test-precedence-1
8021description:
8022	Check a weird precedence case (and POSIX echo)
8023stdin:
8024	test \( -f = -f \)
8025	rv=$?
8026	echo $rv
8027expected-stdout:
8028	0
8029---
8030name: test-option-1
8031description:
8032	Test the test -o operator
8033stdin:
8034	runtest() {
8035		test -o $1; echo $?
8036		[ -o $1 ]; echo $?
8037		[[ -o $1 ]]; echo $?
8038	}
8039	if_test() {
8040		test -o $1 -o -o !$1; echo $?
8041		[ -o $1 -o -o !$1 ]; echo $?
8042		[[ -o $1 || -o !$1 ]]; echo $?
8043		test -o ?$1; echo $?
8044	}
8045	echo 0y $(if_test utf8-mode) =
8046	echo 0n $(if_test utf8-hack) =
8047	echo 1= $(runtest utf8-hack) =
8048	echo 2= $(runtest !utf8-hack) =
8049	echo 3= $(runtest ?utf8-hack) =
8050	set +U
8051	echo 1+ $(runtest utf8-mode) =
8052	echo 2+ $(runtest !utf8-mode) =
8053	echo 3+ $(runtest ?utf8-mode) =
8054	set -U
8055	echo 1- $(runtest utf8-mode) =
8056	echo 2- $(runtest !utf8-mode) =
8057	echo 3- $(runtest ?utf8-mode) =
8058	echo = short flags =
8059	echo 0y $(if_test -U) =
8060	echo 0y $(if_test +U) =
8061	echo 0n $(if_test -_) =
8062	echo 0n $(if_test -U-) =
8063	echo 1= $(runtest -_) =
8064	echo 2= $(runtest !-_) =
8065	echo 3= $(runtest ?-_) =
8066	set +U
8067	echo 1+ $(runtest -U) =
8068	echo 2+ $(runtest !-U) =
8069	echo 3+ $(runtest ?-U) =
8070	echo 1+ $(runtest +U) =
8071	echo 2+ $(runtest !+U) =
8072	echo 3+ $(runtest ?+U) =
8073	set -U
8074	echo 1- $(runtest -U) =
8075	echo 2- $(runtest !-U) =
8076	echo 3- $(runtest ?-U) =
8077	echo 1- $(runtest +U) =
8078	echo 2- $(runtest !+U) =
8079	echo 3- $(runtest ?+U) =
8080expected-stdout:
8081	0y 0 0 0 0 =
8082	0n 1 1 1 1 =
8083	1= 1 1 1 =
8084	2= 1 1 1 =
8085	3= 1 1 1 =
8086	1+ 1 1 1 =
8087	2+ 0 0 0 =
8088	3+ 0 0 0 =
8089	1- 0 0 0 =
8090	2- 1 1 1 =
8091	3- 0 0 0 =
8092	= short flags =
8093	0y 0 0 0 0 =
8094	0y 0 0 0 0 =
8095	0n 1 1 1 1 =
8096	0n 1 1 1 1 =
8097	1= 1 1 1 =
8098	2= 1 1 1 =
8099	3= 1 1 1 =
8100	1+ 1 1 1 =
8101	2+ 0 0 0 =
8102	3+ 0 0 0 =
8103	1+ 1 1 1 =
8104	2+ 0 0 0 =
8105	3+ 0 0 0 =
8106	1- 0 0 0 =
8107	2- 1 1 1 =
8108	3- 0 0 0 =
8109	1- 0 0 0 =
8110	2- 1 1 1 =
8111	3- 0 0 0 =
8112---
8113name: test-varset-1
8114description:
8115	Test the test -v operator
8116stdin:
8117	[[ -v a ]]
8118	rv=$?; echo $((++i)) $rv
8119	a=
8120	[[ -v a ]]
8121	rv=$?; echo $((++i)) $rv
8122	unset a
8123	[[ -v a ]]
8124	rv=$?; echo $((++i)) $rv
8125	a=x
8126	[[ -v a ]]
8127	rv=$?; echo $((++i)) $rv
8128	nameref b=a
8129	[[ -v b ]]
8130	rv=$?; echo $((++i)) $rv
8131	unset a
8132	[[ -v b ]]
8133	rv=$?; echo $((++i)) $rv
8134	x[1]=y
8135	[[ -v x ]]
8136	rv=$?; echo $((++i)) $rv
8137	[[ -v x[0] ]]
8138	rv=$?; echo $((++i)) $rv
8139	[[ -v x[1] ]]
8140	rv=$?; echo $((++i)) $rv
8141	[[ -v x[2] ]]
8142	rv=$?; echo $((++i)) $rv
8143expected-stdout:
8144	1 1
8145	2 0
8146	3 1
8147	4 0
8148	5 0
8149	6 1
8150	7 1
8151	8 1
8152	9 0
8153	10 1
8154---
8155name: test-varset-2
8156description:
8157	test -v works only on scalars
8158stdin:
8159	[[ -v x[*] ]]
8160	echo ok
8161expected-exit: e != 0
8162expected-stderr-pattern:
8163	/unexpected '\*'/
8164---
8165name: test-stnze-1
8166description:
8167	Check that the short form [ $x ] works
8168stdin:
8169	i=0
8170	[ -n $x ]
8171	rv=$?; echo $((++i)) $rv
8172	[ $x ]
8173	rv=$?; echo $((++i)) $rv
8174	[ -n "$x" ]
8175	rv=$?; echo $((++i)) $rv
8176	[ "$x" ]
8177	rv=$?; echo $((++i)) $rv
8178	x=0
8179	[ -n $x ]
8180	rv=$?; echo $((++i)) $rv
8181	[ $x ]
8182	rv=$?; echo $((++i)) $rv
8183	[ -n "$x" ]
8184	rv=$?; echo $((++i)) $rv
8185	[ "$x" ]
8186	rv=$?; echo $((++i)) $rv
8187	x='1 -a 1 = 2'
8188	[ -n $x ]
8189	rv=$?; echo $((++i)) $rv
8190	[ $x ]
8191	rv=$?; echo $((++i)) $rv
8192	[ -n "$x" ]
8193	rv=$?; echo $((++i)) $rv
8194	[ "$x" ]
8195	rv=$?; echo $((++i)) $rv
8196expected-stdout:
8197	1 0
8198	2 1
8199	3 1
8200	4 1
8201	5 0
8202	6 0
8203	7 0
8204	8 0
8205	9 1
8206	10 1
8207	11 0
8208	12 0
8209---
8210name: test-stnze-2
8211description:
8212	Check that the short form [[ $x ]] works (ksh93 extension)
8213stdin:
8214	i=0
8215	[[ -n $x ]]
8216	rv=$?; echo $((++i)) $rv
8217	[[ $x ]]
8218	rv=$?; echo $((++i)) $rv
8219	[[ -n "$x" ]]
8220	rv=$?; echo $((++i)) $rv
8221	[[ "$x" ]]
8222	rv=$?; echo $((++i)) $rv
8223	x=0
8224	[[ -n $x ]]
8225	rv=$?; echo $((++i)) $rv
8226	[[ $x ]]
8227	rv=$?; echo $((++i)) $rv
8228	[[ -n "$x" ]]
8229	rv=$?; echo $((++i)) $rv
8230	[[ "$x" ]]
8231	rv=$?; echo $((++i)) $rv
8232	x='1 -a 1 = 2'
8233	[[ -n $x ]]
8234	rv=$?; echo $((++i)) $rv
8235	[[ $x ]]
8236	rv=$?; echo $((++i)) $rv
8237	[[ -n "$x" ]]
8238	rv=$?; echo $((++i)) $rv
8239	[[ "$x" ]]
8240	rv=$?; echo $((++i)) $rv
8241expected-stdout:
8242	1 1
8243	2 1
8244	3 1
8245	4 1
8246	5 0
8247	6 0
8248	7 0
8249	8 0
8250	9 0
8251	10 0
8252	11 0
8253	12 0
8254---
8255name: test-numeq
8256description:
8257	Check numeric -eq works (R40d regression); spotted by Martijn Dekker
8258stdin:
8259	tst() {
8260		eval "$2"
8261		case $? in
8262		(0) echo yepp 0 \#"$*" ;;
8263		(1) echo nope 1 \#"$*" ;;
8264		(2) echo terr 2 \#"$*" ;;
8265		(*) echo wtf\? $? \#"$*" ;;
8266		esac
8267	}
8268	tst 1 'test 2 -eq 2'
8269	tst 2 'test 2 -eq 2a'
8270	tst 3 'test 2 -eq 3'
8271	tst 4 'test 2 -ne 2'
8272	tst 5 'test 2 -ne 2a'
8273	tst 6 'test 2 -ne 3'
8274	tst 7 'test \! 2 -eq 2'
8275	tst 8 'test \! 2 -eq 2a'
8276	tst 9 'test \! 2 -eq 3'
8277expected-stdout:
8278	yepp 0 #1 test 2 -eq 2
8279	terr 2 #2 test 2 -eq 2a
8280	nope 1 #3 test 2 -eq 3
8281	nope 1 #4 test 2 -ne 2
8282	terr 2 #5 test 2 -ne 2a
8283	yepp 0 #6 test 2 -ne 3
8284	nope 1 #7 test \! 2 -eq 2
8285	terr 2 #8 test \! 2 -eq 2a
8286	yepp 0 #9 test \! 2 -eq 3
8287expected-stderr-pattern:
8288	/bad number/
8289---
8290name: mkshrc-1
8291description:
8292	Check that ~/.mkshrc works correctly.
8293	Part 1: verify user environment is not read (internal)
8294stdin:
8295	echo x $FNORD
8296expected-stdout:
8297	x
8298---
8299name: mkshrc-2a
8300description:
8301	Check that ~/.mkshrc works correctly.
8302	Part 2: verify mkshrc is not read (non-interactive shells)
8303file-setup: file 644 ".mkshrc"
8304	FNORD=42
8305env-setup: !HOME=.!ENV=!
8306stdin:
8307	echo x $FNORD
8308expected-stdout:
8309	x
8310---
8311name: mkshrc-2b
8312description:
8313	Check that ~/.mkshrc works correctly.
8314	Part 2: verify mkshrc can be read (interactive shells)
8315file-setup: file 644 ".mkshrc"
8316	FNORD=42
8317need-ctty: yes
8318arguments: !-i!
8319env-setup: !HOME=.!ENV=!PS1=!
8320stdin:
8321	echo x $FNORD
8322expected-stdout:
8323	x 42
8324expected-stderr-pattern:
8325	/(# )*/
8326---
8327name: mkshrc-3
8328description:
8329	Check that ~/.mkshrc works correctly.
8330	Part 3: verify mkshrc can be turned off
8331file-setup: file 644 ".mkshrc"
8332	FNORD=42
8333env-setup: !HOME=.!ENV=nonexistant!
8334stdin:
8335	echo x $FNORD
8336expected-stdout:
8337	x
8338---
8339name: sh-mode-1
8340description:
8341	Check that sh mode turns braceexpand off
8342	and that that works correctly
8343stdin:
8344	set -o braceexpand
8345	set +o sh
8346	[[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
8347	[[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
8348	echo {a,b,c}
8349	set +o braceexpand
8350	echo {a,b,c}
8351	set -o braceexpand
8352	echo {a,b,c}
8353	set -o sh
8354	echo {a,b,c}
8355	[[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
8356	[[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
8357	set -o braceexpand
8358	echo {a,b,c}
8359	[[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
8360	[[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
8361expected-stdout:
8362	nosh
8363	brex
8364	a b c
8365	{a,b,c}
8366	a b c
8367	{a,b,c}
8368	sh
8369	nobrex
8370	a b c
8371	sh
8372	brex
8373---
8374name: sh-mode-2a
8375description:
8376	Check that posix or sh mode is *not* automatically turned on
8377category: !binsh
8378stdin:
8379	ln -s "$__progname" ksh || cp "$__progname" ksh
8380	ln -s "$__progname" sh || cp "$__progname" sh
8381	ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
8382	ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
8383	for shell in {,-}{,k}sh; do
8384		print -- $shell $(./$shell +l -c \
8385		    '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
8386	done
8387expected-stdout:
8388	sh nosh
8389	ksh nosh
8390	-sh nosh
8391	-ksh nosh
8392---
8393name: sh-mode-2b
8394description:
8395	Check that posix or sh mode *is* automatically turned on
8396category: binsh
8397stdin:
8398	ln -s "$__progname" ksh || cp "$__progname" ksh
8399	ln -s "$__progname" sh || cp "$__progname" sh
8400	ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
8401	ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
8402	for shell in {,-}{,k}sh; do
8403		print -- $shell $(./$shell +l -c \
8404		    '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
8405	done
8406expected-stdout:
8407	sh sh
8408	ksh nosh
8409	-sh sh
8410	-ksh nosh
8411---
8412name: pipeline-1
8413description:
8414	pdksh bug: last command of a pipeline is executed in a
8415	subshell - make sure it still is, scripts depend on it
8416file-setup: file 644 "abcx"
8417file-setup: file 644 "abcy"
8418stdin:
8419	echo *
8420	echo a | while read d; do
8421		echo $d
8422		echo $d*
8423		echo *
8424		set -o noglob
8425		echo $d*
8426		echo *
8427	done
8428	echo *
8429expected-stdout:
8430	abcx abcy
8431	a
8432	abcx abcy
8433	abcx abcy
8434	a*
8435	*
8436	abcx abcy
8437---
8438name: pipeline-2
8439description:
8440	check that co-processes work with TCOMs, TPIPEs and TPARENs
8441category: !nojsig
8442stdin:
8443	"$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done'
8444	"$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done'
8445	"$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done'
8446expected-stdout:
8447	100 hi
8448	200 hi
8449	300 hi
8450---
8451name: pipeline-3
8452description:
8453	Check that PIPESTATUS does what it's supposed to
8454stdin:
8455	echo 1 $PIPESTATUS .
8456	echo 2 ${PIPESTATUS[0]} .
8457	echo 3 ${PIPESTATUS[1]} .
8458	(echo x; exit 12) | (cat; exit 23) | (cat; exit 42)
8459	echo 5 $? , $PIPESTATUS , ${PIPESTATUS[0]} , ${PIPESTATUS[1]} , ${PIPESTATUS[2]} , ${PIPESTATUS[3]} .
8460	echo 6 ${PIPESTATUS[0]} .
8461	set | fgrep PIPESTATUS
8462	echo 8 $(set | fgrep PIPESTATUS) .
8463expected-stdout:
8464	1 0 .
8465	2 0 .
8466	3 .
8467	x
8468	5 42 , 12 , 12 , 23 , 42 , .
8469	6 0 .
8470	PIPESTATUS[0]=0
8471	8 PIPESTATUS[0]=0 PIPESTATUS[1]=0 .
8472---
8473name: pipeline-4
8474description:
8475	Check that "set -o pipefail" does what it's supposed to
8476stdin:
8477	echo 1 "$("$__progname" -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
8478	echo 2 "$("$__progname" -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
8479	echo 3 "$("$__progname" -o pipefail -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
8480	echo 4 "$("$__progname" -o pipefail -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
8481	echo 5 "$("$__progname" -c '(exit 23) | (exit 42) | :; echo $?')" .
8482	echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" .
8483	echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" .
8484	echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" .
8485	echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" .
8486expected-stdout:
8487	1 42 .
8488	2 0 .
8489	3 42 .
8490	4 0 .
8491	5 0 .
8492	6 1 .
8493	7 42 .
8494	8 0 .
8495	9 42 .
8496---
8497name: persist-history-1
8498description:
8499	Check if persistent history saving works
8500category: !no-histfile
8501need-ctty: yes
8502arguments: !-i!
8503env-setup: !ENV=./Env!HISTFILE=hist.file!
8504file-setup: file 644 "Env"
8505	PS1=X
8506stdin:
8507	cat hist.file
8508expected-stdout-pattern:
8509	/cat hist.file/
8510expected-stderr-pattern:
8511	/^X*$/
8512---
8513name: typeset-1
8514description:
8515	Check that typeset -g works correctly
8516stdin:
8517	set -A arrfoo 65
8518	foo() {
8519		typeset -g -Uui16 arrfoo[*]
8520	}
8521	echo before ${arrfoo[0]} .
8522	foo
8523	echo after ${arrfoo[0]} .
8524	set -A arrbar 65
8525	bar() {
8526		echo inside before ${arrbar[0]} .
8527		arrbar[0]=97
8528		echo inside changed ${arrbar[0]} .
8529		typeset -g -Uui16 arrbar[*]
8530		echo inside typeset ${arrbar[0]} .
8531		arrbar[0]=48
8532		echo inside changed ${arrbar[0]} .
8533	}
8534	echo before ${arrbar[0]} .
8535	bar
8536	echo after ${arrbar[0]} .
8537expected-stdout:
8538	before 65 .
8539	after 16#41 .
8540	before 65 .
8541	inside before 65 .
8542	inside changed 97 .
8543	inside typeset 16#61 .
8544	inside changed 16#30 .
8545	after 16#30 .
8546---
8547name: typeset-2
8548description:
8549	Check that typeset -p on arrays works correctly
8550stdin:
8551	set -A x -- a b c
8552	echo =
8553	typeset -p x
8554	echo =
8555	typeset -p x[1]
8556expected-stdout:
8557	=
8558	set -A x
8559	typeset x[0]=a
8560	typeset x[1]=b
8561	typeset x[2]=c
8562	=
8563	typeset x[1]=b
8564---
8565name: typeset-padding-1
8566description:
8567	Check if left/right justification works as per TFM
8568stdin:
8569	typeset -L10 ln=0hall0
8570	typeset -R10 rn=0hall0
8571	typeset -ZL10 lz=0hall0
8572	typeset -ZR10 rz=0hall0
8573	typeset -Z10 rx=" hallo "
8574	echo "<$ln> <$rn> <$lz> <$rz> <$rx>"
8575expected-stdout:
8576	<0hall0    > <    0hall0> <hall0     > <00000hall0> <0000 hallo>
8577---
8578name: typeset-padding-2
8579description:
8580	Check if base-!10 integers are padded right
8581stdin:
8582	typeset -Uui16 -L9 ln=16#1
8583	typeset -Uui16 -R9 rn=16#1
8584	typeset -Uui16 -Z9 zn=16#1
8585	typeset -L9 ls=16#1
8586	typeset -R9 rs=16#1
8587	typeset -Z9 zs=16#1
8588	echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
8589expected-stdout:
8590	<16#1     > <     16#1> <16#000001> <16#1     > <     16#1> <0000016#1>
8591---
8592name: typeset-padding-3
8593description:
8594	Check for a regression in which UTF-8 wasn’t left-padded right
8595stdin:
8596	set -U
8597	nl=$'\n'
8598	typeset -L20 x='.  ak'
8599	typeset -R20 y='.  ak'
8600	print -r -- "<$x> (1$nl<12345678910 345678920$nl<$y> 1)"
8601	typeset -L20 x='.  aẞ'
8602	typeset -R20 y='.  aẞ'
8603	print -r -- "<$x> (2$nl<12345678910 345678920$nl<$y> 2)"
8604expected-stdout:
8605	<.  ak               > (1
8606	<12345678910 345678920
8607	<               .  ak> 1)
8608	<.  aẞ               > (2
8609	<12345678910 345678920
8610	<               .  aẞ> 2)
8611---
8612name: utf8bom-1
8613description:
8614	Check that the UTF-8 Byte Order Mark is ignored as the first
8615	multibyte character of the shell input (with -c, from standard
8616	input, as file, or as eval argument), but nowhere else
8617# breaks on Mac OSX (HFS+ non-standard UTF-8 canonical decomposition)
8618category: !os:darwin,!shell:ebcdic-yes
8619stdin:
8620	mkdir foo
8621	print '#!/bin/sh\necho ohne' >foo/fnord
8622	print '#!/bin/sh\necho mit' >foo/fnord
8623	print 'fnord\nfnord\nfnord\nfnord' >foo/bar
8624	print eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo
8625	set -A anzahl -- foo/*
8626	echo got ${#anzahl[*]} files
8627	chmod +x foo/*
8628	export PATH=$(pwd)/foo$PATHSEP$PATH
8629	"$__progname" -c 'fnord'
8630	echo =
8631	"$__progname" -c 'fnord; fnord; fnord; fnord'
8632	echo =
8633	"$__progname" foo/bar
8634	echo =
8635	"$__progname" <foo/bar
8636	echo =
8637	"$__progname" foo/zoo
8638	echo =
8639	"$__progname" -c 'echo : $(fnord)'
8640	rm -rf foo
8641expected-stdout:
8642	got 4 files
8643	ohne
8644	=
8645	ohne
8646	ohne
8647	mit
8648	ohne
8649	=
8650	ohne
8651	ohne
8652	mit
8653	ohne
8654	=
8655	ohne
8656	ohne
8657	mit
8658	ohne
8659	=
8660	ohne
8661	ohne
8662	mit
8663	ohne
8664	=
8665	: ohne
8666---
8667name: utf8bom-2
8668description:
8669	Check that we can execute BOM-shebangs (failures not fatal)
8670	XXX if the OS can already execute them, we lose
8671	note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
8672	note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
8673	XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan)
8674need-pass: no
8675category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh
8676env-setup: !FOO=BAR!
8677stdin:
8678	print '#!'"$__progname"'\nprint "1 a=$ENV{FOO}";' >t1
8679	print '#!'"$__progname"'\nprint "2 a=$ENV{FOO}";' >t2
8680	print '#!'"$__perlname"'\nprint "3 a=$ENV{FOO}\n";' >t3
8681	print '#!'"$__perlname"'\nprint "4 a=$ENV{FOO}\n";' >t4
8682	chmod +x t?
8683	./t1
8684	./t2
8685	./t3
8686	./t4
8687expected-stdout:
8688	1 a=/nonexistant{FOO}
8689	2 a=/nonexistant{FOO}
8690	3 a=BAR
8691	4 a=BAR
8692expected-stderr-pattern:
8693	/(Unrecognized character .... ignored at \..t4 line 1)*/
8694---
8695name: utf8opt-1
8696description:
8697	Check that the utf8-mode flag is not set at non-interactive startup
8698env-setup: !PS1=!PS2=!LC_CTYPE=@utflocale@!
8699stdin:
8700	if [[ $- = *U* ]]; then
8701		echo is set
8702	else
8703		echo is not set
8704	fi
8705expected-stdout:
8706	is not set
8707---
8708name: utf8opt-2
8709description:
8710	Check that the utf8-mode flag is set at interactive startup.
8711	If your OS is old, try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh
8712need-pass: no
8713category: !noutf8
8714need-ctty: yes
8715arguments: !-i!
8716env-setup: !PS1=!PS2=!LC_CTYPE=@utflocale@!
8717stdin:
8718	if [[ $- = *U* ]]; then
8719		echo is set
8720	else
8721		echo is not set
8722	fi
8723expected-stdout:
8724	is set
8725expected-stderr-pattern:
8726	/(# )*/
8727---
8728name: utf8opt-3a
8729description:
8730	Ensure ±U on the command line is honoured
8731	(these two tests may pass falsely depending on CPPFLAGS)
8732stdin:
8733	export i=0
8734	code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
8735	let i++; "$__progname" -U -c "$code"
8736	let i++; "$__progname" +U -c "$code"
8737	echo $((++i)) done
8738expected-stdout:
8739	1 on
8740	2 off
8741	3 done
8742---
8743name: utf8opt-3b
8744description:
8745	Ensure ±U on the command line is honoured, interactive shells
8746need-ctty: yes
8747stdin:
8748	export i=0
8749	code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
8750	let i++; "$__progname" -U -ic "$code"
8751	let i++; "$__progname" +U -ic "$code"
8752	echo $((++i)) done
8753expected-stdout:
8754	1 on
8755	2 off
8756	3 done
8757---
8758name: utf8bug-1
8759description:
8760	Ensure trailing combining characters are not lost
8761stdin:
8762	set -U
8763	a=a
8764	b=$'\u0301'
8765	x=$a$b
8766	print -r -- "<e$x>"
8767	x=$a
8768	x+=$b
8769	print -r -- "<e$x>"
8770	b=$'\u0301'b
8771	x=$a
8772	x+=$b
8773	print -r -- "<e$x>"
8774expected-stdout:
8775	<eá>
8776	<eá>
8777	<eáb>
8778---
8779name: aliases-1
8780description:
8781	Check if built-in shell aliases are okay
8782stdin:
8783	alias
8784	typeset -f
8785expected-stdout:
8786	autoload='\\builtin typeset -fu'
8787	functions='\\builtin typeset -f'
8788	hash='\\builtin alias -t'
8789	history='\\builtin fc -l'
8790	integer='\\builtin typeset -i'
8791	local='\\builtin typeset'
8792	login='\\builtin exec login'
8793	nameref='\\builtin typeset -n'
8794	nohup='nohup '
8795	r='\\builtin fc -e -'
8796	type='\\builtin whence -v'
8797---
8798name: aliases-2b
8799description:
8800	Check if “set -o sh” does not influence built-in aliases
8801arguments: !-o!sh!
8802stdin:
8803	alias
8804	typeset -f
8805expected-stdout:
8806	autoload='\\builtin typeset -fu'
8807	functions='\\builtin typeset -f'
8808	hash='\\builtin alias -t'
8809	history='\\builtin fc -l'
8810	integer='\\builtin typeset -i'
8811	local='\\builtin typeset'
8812	login='\\builtin exec login'
8813	nameref='\\builtin typeset -n'
8814	nohup='nohup '
8815	r='\\builtin fc -e -'
8816	type='\\builtin whence -v'
8817---
8818name: aliases-3b
8819description:
8820	Check if running as sh does not influence built-in aliases
8821stdin:
8822	cp "$__progname" sh
8823	./sh -c 'alias; typeset -f'
8824	rm -f sh
8825expected-stdout:
8826	autoload='\\builtin typeset -fu'
8827	functions='\\builtin typeset -f'
8828	hash='\\builtin alias -t'
8829	history='\\builtin fc -l'
8830	integer='\\builtin typeset -i'
8831	local='\\builtin typeset'
8832	login='\\builtin exec login'
8833	nameref='\\builtin typeset -n'
8834	nohup='nohup '
8835	r='\\builtin fc -e -'
8836	type='\\builtin whence -v'
8837---
8838name: aliases-cmdline
8839description:
8840	Check that aliases work from the command line (Debian #517009)
8841	Note that due to the nature of the lexing process, defining
8842	aliases in COMSUBs then immediately using them, and things
8843	like 'alias foo=bar && foo', still fail.
8844stdin:
8845	"$__progname" -c $'alias a="echo OK"\na'
8846expected-stdout:
8847	OK
8848---
8849name: aliases-funcdef-1
8850description:
8851	Check if POSIX functions take precedences over aliases
8852stdin:
8853	alias foo='echo makro'
8854	foo() {
8855		echo funktion
8856	}
8857	foo
8858expected-stdout:
8859	makro
8860---
8861name: aliases-funcdef-2
8862description:
8863	Check if POSIX functions take precedences over aliases
8864stdin:
8865	alias foo='echo makro'
8866	foo () {
8867		echo funktion
8868	}
8869	foo
8870expected-stdout:
8871	makro
8872---
8873name: aliases-funcdef-3
8874description:
8875	Check if aliases take precedences over Korn functions
8876stdin:
8877	alias foo='echo makro'
8878	function foo {
8879		echo funktion
8880	}
8881	foo
8882expected-stdout:
8883	makro
8884---
8885name: aliases-funcdef-4
8886description:
8887	Functions should only take over if actually being defined
8888stdin:
8889	alias local
8890	:|| local() { :; }
8891	alias local
8892expected-stdout:
8893	local='\\builtin typeset'
8894	local='\\builtin typeset'
8895---
8896name: arrays-1
8897description:
8898	Check if Korn Shell arrays work as expected
8899stdin:
8900	v="c d"
8901	set -A foo -- a \$v "$v" '$v' b
8902	echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8903expected-stdout:
8904	5|a|$v|c d|$v|b|
8905---
8906name: arrays-2a
8907description:
8908	Check if bash-style arrays work as expected
8909stdin:
8910	v="c d"
8911	foo=(a \$v "$v" '$v' b)
8912	echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8913expected-stdout:
8914	5|a|$v|c d|$v|b|
8915---
8916name: arrays-2b
8917description:
8918	Check if bash-style arrays work as expected, with newlines
8919stdin:
8920	print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp
8921	chmod +x pfp
8922	test -n "$ZSH_VERSION" && setopt KSH_ARRAYS
8923	v="e f"
8924	foo=(a
8925		bc
8926		d \$v "$v" '$v' g
8927	)
8928	./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8929	foo=(a\
8930		bc
8931		d \$v "$v" '$v' g
8932	)
8933	./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8934	foo=(a\
8935	bc\\
8936		d \$v "$v" '$v'
8937	g)
8938	./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8939expected-stdout:
8940	7|a|bc|d|$v|e f|$v|g|
8941	7|a|bc|d|$v|e f|$v|g|
8942	6|abc\|d|$v|e f|$v|g||
8943---
8944name: arrays-3
8945description:
8946	Check if array bounds are uint32_t
8947stdin:
8948	set -A foo a b c
8949	foo[4097]=d
8950	foo[2147483637]=e
8951	echo ${foo[*]}
8952	foo[-1]=f
8953	echo ${foo[4294967295]} g ${foo[*]}
8954expected-stdout:
8955	a b c d e
8956	f g a b c d e f
8957---
8958name: arrays-4
8959description:
8960	Check if Korn Shell arrays with specified indices work as expected
8961stdin:
8962	v="c d"
8963	set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b
8964	echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
8965	# we don't want this at all:
8966	#	5|a|$v|c d||$v|b|
8967	set -A arr "[5]=meh"
8968	echo "<${arr[0]}><${arr[5]}>"
8969expected-stdout:
8970	5|[1]=$v|[2]=c d|[4]=$v|[0]=a|[5]=b||
8971	<[5]=meh><>
8972---
8973name: arrays-5
8974description:
8975	Check if bash-style arrays with specified indices work as expected
8976	(taken out temporarily to fix arrays-4; see also arrays-9a comment)
8977category: disabled
8978stdin:
8979	v="c d"
8980	foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b)
8981	echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
8982	x=([128]=foo bar baz)
8983	echo k= ${!x[*]} .
8984	echo v= ${x[*]} .
8985	# Check that we do not break this by globbing
8986	:>b=blah
8987	bleh=5
8988	typeset -a arr
8989	arr+=([bleh]=blah)
8990	echo "<${arr[0]}><${arr[5]}>"
8991expected-stdout:
8992	5|a|$v|c d||$v|b|
8993	k= 128 129 130 .
8994	v= foo bar baz .
8995	<><blah>
8996---
8997name: arrays-6
8998description:
8999	Check if we can get the array keys (indices) for indexed arrays,
9000	Korn shell style
9001stdin:
9002	of() {
9003		i=0
9004		for x in "$@"; do
9005			echo -n "$((i++))<$x>"
9006		done
9007		echo
9008	}
9009	foo[1]=eins
9010	set | grep '^foo'
9011	echo =
9012	foo[0]=zwei
9013	foo[4]=drei
9014	set | grep '^foo'
9015	echo =
9016	echo a $(of ${foo[*]}) = $(of ${bar[*]}) a
9017	echo b $(of "${foo[*]}") = $(of "${bar[*]}") b
9018	echo c $(of ${foo[@]}) = $(of ${bar[@]}) c
9019	echo d $(of "${foo[@]}") = $(of "${bar[@]}") d
9020	echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e
9021	echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f
9022	echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g
9023	echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h
9024expected-stdout:
9025	foo[1]=eins
9026	=
9027	foo[0]=zwei
9028	foo[1]=eins
9029	foo[4]=drei
9030	=
9031	a 0<zwei>1<eins>2<drei> = a
9032	b 0<zwei eins drei> = 0<> b
9033	c 0<zwei>1<eins>2<drei> = c
9034	d 0<zwei>1<eins>2<drei> = d
9035	e 0<0>1<1>2<4> = e
9036	f 0<0 1 4> = 0<> f
9037	g 0<0>1<1>2<4> = g
9038	h 0<0>1<1>2<4> = h
9039---
9040name: arrays-7
9041description:
9042	Check if we can get the array keys (indices) for indexed arrays,
9043	Korn shell style, in some corner cases
9044stdin:
9045	echo !arz: ${!arz}
9046	echo !arz[0]: ${!arz[0]}
9047	echo !arz[1]: ${!arz[1]}
9048	arz=foo
9049	echo !arz: ${!arz}
9050	echo !arz[0]: ${!arz[0]}
9051	echo !arz[1]: ${!arz[1]}
9052	unset arz
9053	echo !arz: ${!arz}
9054	echo !arz[0]: ${!arz[0]}
9055	echo !arz[1]: ${!arz[1]}
9056expected-stdout:
9057	!arz: arz
9058	!arz[0]: arz[0]
9059	!arz[1]: arz[1]
9060	!arz: arz
9061	!arz[0]: arz[0]
9062	!arz[1]: arz[1]
9063	!arz: arz
9064	!arz[0]: arz[0]
9065	!arz[1]: arz[1]
9066---
9067name: arrays-8
9068description:
9069	Check some behavioural rules for arrays.
9070stdin:
9071	fna() {
9072		set -A aa 9
9073	}
9074	fnb() {
9075		typeset ab
9076		set -A ab 9
9077	}
9078	fnc() {
9079		typeset ac
9080		set -A ac 91
9081		unset ac
9082		set -A ac 92
9083	}
9084	fnd() {
9085		set +A ad 9
9086	}
9087	fne() {
9088		unset ae
9089		set +A ae 9
9090	}
9091	fnf() {
9092		unset af[0]
9093		set +A af 9
9094	}
9095	fng() {
9096		unset ag[*]
9097		set +A ag 9
9098	}
9099	set -A aa 1 2
9100	set -A ab 1 2
9101	set -A ac 1 2
9102	set -A ad 1 2
9103	set -A ae 1 2
9104	set -A af 1 2
9105	set -A ag 1 2
9106	set -A ah 1 2
9107	typeset -Z3 aa ab ac ad ae af ag
9108	print 1a ${aa[*]} .
9109	print 1b ${ab[*]} .
9110	print 1c ${ac[*]} .
9111	print 1d ${ad[*]} .
9112	print 1e ${ae[*]} .
9113	print 1f ${af[*]} .
9114	print 1g ${ag[*]} .
9115	print 1h ${ah[*]} .
9116	fna
9117	fnb
9118	fnc
9119	fnd
9120	fne
9121	fnf
9122	fng
9123	typeset -Z5 ah[*]
9124	print 2a ${aa[*]} .
9125	print 2b ${ab[*]} .
9126	print 2c ${ac[*]} .
9127	print 2d ${ad[*]} .
9128	print 2e ${ae[*]} .
9129	print 2f ${af[*]} .
9130	print 2g ${ag[*]} .
9131	print 2h ${ah[*]} .
9132expected-stdout:
9133	1a 001 002 .
9134	1b 001 002 .
9135	1c 001 002 .
9136	1d 001 002 .
9137	1e 001 002 .
9138	1f 001 002 .
9139	1g 001 002 .
9140	1h 1 2 .
9141	2a 9 .
9142	2b 001 002 .
9143	2c 92 .
9144	2d 009 002 .
9145	2e 9 .
9146	2f 9 002 .
9147	2g 009 .
9148	2h 00001 00002 .
9149---
9150name: arrays-9a
9151description:
9152	Check that we can concatenate arrays
9153stdin:
9154	unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} .
9155	unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} .
9156#	unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} .
9157expected-stdout:
9158	1 0 1 : bar baz .
9159	2 0 1 2 : foo bar baz .
9160#	3 0 2 3 5 : bar foo baz quux .
9161---
9162name: arrays-9b
9163description:
9164	Check that we can concatenate parameters too
9165stdin:
9166	unset foo; foo=bar; foo+=baz; echo 1 $foo .
9167	unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo .
9168expected-stdout:
9169	1 barbaz .
9170	2 16#a20 .
9171---
9172name: arrassign-basic
9173description:
9174	Check basic whitespace conserving properties of wdarrassign
9175stdin:
9176	a=($(echo a  b))
9177	b=($(echo "a  b"))
9178	c=("$(echo "a  b")")
9179	d=("$(echo a  b)")
9180	a+=($(echo c  d))
9181	b+=($(echo "c  d"))
9182	c+=("$(echo "c  d")")
9183	d+=("$(echo c  d)")
9184	echo ".a:${a[0]}.${a[1]}.${a[2]}.${a[3]}:"
9185	echo ".b:${b[0]}.${b[1]}.${b[2]}.${b[3]}:"
9186	echo ".c:${c[0]}.${c[1]}.${c[2]}.${c[3]}:"
9187	echo ".d:${d[0]}.${d[1]}.${d[2]}.${d[3]}:"
9188expected-stdout:
9189	.a:a.b.c.d:
9190	.b:a.b.c.d:
9191	.c:a  b.c  d..:
9192	.d:a b.c d..:
9193---
9194name: arrassign-eol
9195description:
9196	Commands after array assignments are not permitted
9197stdin:
9198	foo=(a b) env
9199expected-exit: e != 0
9200expected-stderr-pattern:
9201	/syntax error: unexpected 'env'/
9202---
9203name: arrassign-fnc-none
9204description:
9205	Check locality of array access inside a function
9206stdin:
9207	function fn {
9208		x+=(f)
9209		echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9210	}
9211	function rfn {
9212		if [[ -n $BASH_VERSION ]]; then
9213			y=()
9214		else
9215			set -A y
9216		fi
9217		y+=(f)
9218		echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9219	}
9220	x=(m m)
9221	y=(m m)
9222	echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9223	fn
9224	echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9225	fn
9226	echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9227	echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9228	rfn
9229	echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9230	rfn
9231	echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9232expected-stdout:
9233	.f0:m.m..:
9234	.fn:m.m.f.:
9235	.f1:m.m.f.:
9236	.fn:m.m.f.f:
9237	.f2:m.m.f.f:
9238	.rf0:m.m..:
9239	.rfn:f...:
9240	.rf1:f...:
9241	.rfn:f...:
9242	.rf2:f...:
9243---
9244name: arrassign-fnc-local
9245description:
9246	Check locality of array access inside a function
9247	with the bash/mksh/ksh93 local/typeset keyword
9248	(note: ksh93 has no local; typeset works only in FKSH)
9249stdin:
9250	function fn {
9251		typeset x
9252		x+=(f)
9253		echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9254	}
9255	function rfn {
9256		if [[ -n $BASH_VERSION ]]; then
9257			y=()
9258		else
9259			set -A y
9260		fi
9261		typeset y
9262		y+=(f)
9263		echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9264	}
9265	function fnr {
9266		typeset z
9267		if [[ -n $BASH_VERSION ]]; then
9268			z=()
9269		else
9270			set -A z
9271		fi
9272		z+=(f)
9273		echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9274	}
9275	x=(m m)
9276	y=(m m)
9277	z=(m m)
9278	echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9279	fn
9280	echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9281	fn
9282	echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9283	echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9284	rfn
9285	echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9286	rfn
9287	echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9288	echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9289	fnr
9290	echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9291	fnr
9292	echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9293expected-stdout:
9294	.f0:m.m..:
9295	.fn:f...:
9296	.f1:m.m..:
9297	.fn:f...:
9298	.f2:m.m..:
9299	.rf0:m.m..:
9300	.rfn:f...:
9301	.rf1:...:
9302	.rfn:f...:
9303	.rf2:...:
9304	.f0r:m.m..:
9305	.fnr:f...:
9306	.f1r:m.m..:
9307	.fnr:f...:
9308	.f2r:m.m..:
9309---
9310name: arrassign-fnc-global
9311description:
9312	Check locality of array access inside a function
9313	with the bash4/mksh/yash/zsh typeset -g keyword
9314stdin:
9315	function fn {
9316		typeset -g x
9317		x+=(f)
9318		echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9319	}
9320	function rfn {
9321		set -A y
9322		typeset -g y
9323		y+=(f)
9324		echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9325	}
9326	function fnr {
9327		typeset -g z
9328		set -A z
9329		z+=(f)
9330		echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9331	}
9332	x=(m m)
9333	y=(m m)
9334	z=(m m)
9335	echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9336	fn
9337	echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9338	fn
9339	echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9340	echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9341	rfn
9342	echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9343	rfn
9344	echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9345	echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9346	fnr
9347	echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9348	fnr
9349	echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9350expected-stdout:
9351	.f0:m.m..:
9352	.fn:m.m.f.:
9353	.f1:m.m.f.:
9354	.fn:m.m.f.f:
9355	.f2:m.m.f.f:
9356	.rf0:m.m..:
9357	.rfn:f...:
9358	.rf1:f...:
9359	.rfn:f...:
9360	.rf2:f...:
9361	.f0r:m.m..:
9362	.fnr:f...:
9363	.f1r:f...:
9364	.fnr:f...:
9365	.f2r:f...:
9366---
9367name: strassign-fnc-none
9368description:
9369	Check locality of string access inside a function
9370stdin:
9371	function fn {
9372		x+=f
9373		echo ".fn:$x:"
9374	}
9375	function rfn {
9376		y=
9377		y+=f
9378		echo ".rfn:$y:"
9379	}
9380	x=m
9381	y=m
9382	echo ".f0:$x:"
9383	fn
9384	echo ".f1:$x:"
9385	fn
9386	echo ".f2:$x:"
9387	echo ".rf0:$y:"
9388	rfn
9389	echo ".rf1:$y:"
9390	rfn
9391	echo ".rf2:$y:"
9392expected-stdout:
9393	.f0:m:
9394	.fn:mf:
9395	.f1:mf:
9396	.fn:mff:
9397	.f2:mff:
9398	.rf0:m:
9399	.rfn:f:
9400	.rf1:f:
9401	.rfn:f:
9402	.rf2:f:
9403---
9404name: strassign-fnc-local
9405description:
9406	Check locality of string access inside a function
9407	with the bash/mksh/ksh93 local/typeset keyword
9408	(note: ksh93 has no local; typeset works only in FKSH)
9409stdin:
9410	function fn {
9411		typeset x
9412		x+=f
9413		echo ".fn:$x:"
9414	}
9415	function rfn {
9416		y=
9417		typeset y
9418		y+=f
9419		echo ".rfn:$y:"
9420	}
9421	function fnr {
9422		typeset z
9423		z=
9424		z+=f
9425		echo ".fnr:$z:"
9426	}
9427	x=m
9428	y=m
9429	z=m
9430	echo ".f0:$x:"
9431	fn
9432	echo ".f1:$x:"
9433	fn
9434	echo ".f2:$x:"
9435	echo ".rf0:$y:"
9436	rfn
9437	echo ".rf1:$y:"
9438	rfn
9439	echo ".rf2:$y:"
9440	echo ".f0r:$z:"
9441	fnr
9442	echo ".f1r:$z:"
9443	fnr
9444	echo ".f2r:$z:"
9445expected-stdout:
9446	.f0:m:
9447	.fn:f:
9448	.f1:m:
9449	.fn:f:
9450	.f2:m:
9451	.rf0:m:
9452	.rfn:f:
9453	.rf1::
9454	.rfn:f:
9455	.rf2::
9456	.f0r:m:
9457	.fnr:f:
9458	.f1r:m:
9459	.fnr:f:
9460	.f2r:m:
9461---
9462name: strassign-fnc-global
9463description:
9464	Check locality of string access inside a function
9465	with the bash4/mksh/yash/zsh typeset -g keyword
9466stdin:
9467	function fn {
9468		typeset -g x
9469		x+=f
9470		echo ".fn:$x:"
9471	}
9472	function rfn {
9473		y=
9474		typeset -g y
9475		y+=f
9476		echo ".rfn:$y:"
9477	}
9478	function fnr {
9479		typeset -g z
9480		z=
9481		z+=f
9482		echo ".fnr:$z:"
9483	}
9484	x=m
9485	y=m
9486	z=m
9487	echo ".f0:$x:"
9488	fn
9489	echo ".f1:$x:"
9490	fn
9491	echo ".f2:$x:"
9492	echo ".rf0:$y:"
9493	rfn
9494	echo ".rf1:$y:"
9495	rfn
9496	echo ".rf2:$y:"
9497	echo ".f0r:$z:"
9498	fnr
9499	echo ".f1r:$z:"
9500	fnr
9501	echo ".f2r:$z:"
9502expected-stdout:
9503	.f0:m:
9504	.fn:mf:
9505	.f1:mf:
9506	.fn:mff:
9507	.f2:mff:
9508	.rf0:m:
9509	.rfn:f:
9510	.rf1:f:
9511	.rfn:f:
9512	.rf2:f:
9513	.f0r:m:
9514	.fnr:f:
9515	.f1r:f:
9516	.fnr:f:
9517	.f2r:f:
9518---
9519name: unset-fnc-local-ksh
9520description:
9521	Check that “unset” removes a previous “local”
9522	(ksh93 syntax compatible version); apparently,
9523	there are shells which fail this?
9524stdin:
9525	function f {
9526		echo f0: $x
9527		typeset x
9528		echo f1: $x
9529		x=fa
9530		echo f2: $x
9531		unset x
9532		echo f3: $x
9533		x=fb
9534		echo f4: $x
9535	}
9536	x=o
9537	echo before: $x
9538	f
9539	echo after: $x
9540expected-stdout:
9541	before: o
9542	f0: o
9543	f1:
9544	f2: fa
9545	f3: o
9546	f4: fb
9547	after: fb
9548---
9549name: unset-fnc-local-sh
9550description:
9551	Check that “unset” removes a previous “local”
9552	(Debian Policy §10.4 sh version); apparently,
9553	there are shells which fail this?
9554stdin:
9555	f() {
9556		echo f0: $x
9557		local x
9558		echo f1: $x
9559		x=fa
9560		echo f2: $x
9561		unset x
9562		echo f3: $x
9563		x=fb
9564		echo f4: $x
9565	}
9566	x=o
9567	echo before: $x
9568	f
9569	echo after: $x
9570expected-stdout:
9571	before: o
9572	f0: o
9573	f1:
9574	f2: fa
9575	f3: o
9576	f4: fb
9577	after: fb
9578---
9579name: varexpand-substr-1
9580description:
9581	Check if bash-style substring expansion works
9582	when using positive numerics
9583stdin:
9584	x=abcdefghi
9585	typeset -i y=123456789
9586	typeset -i 16 z=123456789	# 16#75bcd15
9587	echo a t${x:2:2} ${y:2:3} ${z:2:3} a
9588	echo b ${x::3} ${y::3} ${z::3} b
9589	echo c ${x:2:} ${y:2:} ${z:2:} c
9590	echo d ${x:2} ${y:2} ${z:2} d
9591	echo e ${x:2:6} ${y:2:6} ${z:2:7} e
9592	echo f ${x:2:7} ${y:2:7} ${z:2:8} f
9593	echo g ${x:2:8} ${y:2:8} ${z:2:9} g
9594expected-stdout:
9595	a tcd 345 #75 a
9596	b abc 123 16# b
9597	c c
9598	d cdefghi 3456789 #75bcd15 d
9599	e cdefgh 345678 #75bcd1 e
9600	f cdefghi 3456789 #75bcd15 f
9601	g cdefghi 3456789 #75bcd15 g
9602---
9603name: varexpand-substr-2
9604description:
9605	Check if bash-style substring expansion works
9606	when using negative numerics or expressions
9607stdin:
9608	x=abcdefghi
9609	typeset -i y=123456789
9610	typeset -i 16 z=123456789	# 16#75bcd15
9611	n=2
9612	echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
9613	echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
9614	echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
9615	echo d t${x: n:2} ${y: n:3} ${z: n:3} d
9616expected-stdout:
9617	a cde 345 #75 a
9618	b cde 345 #75 b
9619	c h 8 1 c
9620	d tcd 345 #75 d
9621---
9622name: varexpand-substr-3
9623description:
9624	Check that some things that work in bash fail.
9625	This is by design. Oh and vice versa, nowadays.
9626stdin:
9627	export x=abcdefghi n=2
9628	"$__progname" -c 'echo v${x:(n)}x'
9629	"$__progname" -c 'echo w${x: n}x'
9630	"$__progname" -c 'echo x${x:n}x'
9631	"$__progname" -c 'echo y${x:}x'
9632	"$__progname" -c 'echo z${x}x'
9633	# next fails only in bash
9634	"$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $?
9635expected-stdout:
9636	vcdefghix
9637	wcdefghix
9638	zabcdefghix
9639	0
9640expected-stderr-pattern:
9641	/x:n.*bad substitution.*\n.*bad substitution/
9642---
9643name: varexpand-substr-4
9644description:
9645	Check corner cases for substring expansion
9646stdin:
9647	x=abcdefghi
9648	integer y=2
9649	echo a ${x:(y == 1 ? 2 : 3):4} a
9650expected-stdout:
9651	a defg a
9652---
9653name: varexpand-substr-5A
9654description:
9655	Check that substring expansions work on characters
9656stdin:
9657	set +U
9658	x=mäh
9659	echo a ${x::1} ${x: -1} a
9660	echo b ${x::3} ${x: -3} b
9661	echo c ${x:1:2} ${x: -3:2} c
9662	echo d ${#x} d
9663expected-stdout:
9664	a m h a
9665	b mä äh b
9666	c ä ä c
9667	d 4 d
9668---
9669name: varexpand-substr-5W
9670description:
9671	Check that substring expansions work on characters
9672stdin:
9673	set -U
9674	x=mäh
9675	echo a ${x::1} ${x: -1} a
9676	echo b ${x::2} ${x: -2} b
9677	echo c ${x:1:1} ${x: -2:1} c
9678	echo d ${#x} d
9679expected-stdout:
9680	a m h a
9681	b mä äh b
9682	c ä ä c
9683	d 3 d
9684---
9685name: varexpand-substr-6
9686description:
9687	Check that string substitution works correctly
9688stdin:
9689	foo=1
9690	bar=2
9691	baz=qwertyuiop
9692	echo a ${baz: foo: bar}
9693	echo b ${baz: foo: $bar}
9694	echo c ${baz: $foo: bar}
9695	echo d ${baz: $foo: $bar}
9696expected-stdout:
9697	a we
9698	b we
9699	c we
9700	d we
9701---
9702name: varexpand-special-hash
9703description:
9704	Check special ${var@x} expansion for x=hash
9705category: !shell:ebcdic-yes
9706stdin:
9707	typeset -i8 foo=10
9708	bar=baz
9709	unset baz
9710	print ${foo@#} ${bar@#} ${baz@#} .
9711expected-stdout:
9712	9B15FBFB CFBDD32B 00000000 .
9713---
9714name: varexpand-special-hash-ebcdic
9715description:
9716	Check special ${var@x} expansion for x=hash
9717category: !shell:ebcdic-no
9718stdin:
9719	typeset -i8 foo=10
9720	bar=baz
9721	unset baz
9722	print ${foo@#} ${bar@#} ${baz@#} .
9723expected-stdout:
9724	016AE33D 9769C4AF 00000000 .
9725---
9726name: varexpand-special-quote
9727description:
9728	Check special ${var@Q} expansion for quoted strings
9729category: !shell:faux-ebcdic
9730stdin:
9731	set +U
9732	i=x
9733	j=a\ b
9734	k=$'c
9735	d\xA0''e€f'
9736	print -r -- "<i=$i j=$j k=$k>"
9737	s="u=${i@Q} v=${j@Q} w=${k@Q}"
9738	print -r -- "s=\"$s\""
9739	eval "$s"
9740	typeset -p u v w
9741expected-stdout:
9742	<i=x j=a b k=c
9743	d�e€f>
9744	s="u=x v='a b' w=$'c\nd\240e\u20ACf'"
9745	typeset u=x
9746	typeset v='a b'
9747	typeset w=$'c\nd\240e\u20ACf'
9748---
9749name: varexpand-special-quote-faux-EBCDIC
9750description:
9751	Check special ${var@Q} expansion for quoted strings
9752category: shell:faux-ebcdic
9753stdin:
9754	set +U
9755	i=x
9756	j=a\ b
9757	k=$'c
9758	d\xA0''e€f'
9759	print -r -- "<i=$i j=$j k=$k>"
9760	s="u=${i@Q} v=${j@Q} w=${k@Q}"
9761	print -r -- "s=\"$s\""
9762	eval "$s"
9763	typeset -p u v w
9764expected-stdout:
9765	<i=x j=a b k=c
9766	d�e€f>
9767	s="u=x v='a b' w=$'c\nd�e\u20ACf'"
9768	typeset u=x
9769	typeset v='a b'
9770	typeset w=$'c\nd�e\u20ACf'
9771---
9772name: varexpand-null-1
9773description:
9774	Ensure empty strings expand emptily
9775stdin:
9776	print s ${a} . ${b} S
9777	print t ${a#?} . ${b%?} T
9778	print r ${a=} . ${b/c/d} R
9779	print q
9780	print s "${a}" . "${b}" S
9781	print t "${a#?}" . "${b%?}" T
9782	print r "${a=}" . "${b/c/d}" R
9783expected-stdout:
9784	s . S
9785	t . T
9786	r . R
9787	q
9788	s  .  S
9789	t  .  T
9790	r  .  R
9791---
9792name: varexpand-null-2
9793description:
9794	Ensure empty strings, when quoted, are expanded as empty strings
9795stdin:
9796	print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
9797	chmod +x pfs
9798	./pfs 1 "${a}" 2 "${a#?}" + "${b%?}" 3 "${a=}" + "${b/c/d}"
9799	echo .
9800expected-stdout:
9801	<1> <> <2> <> <+> <> <3> <> <+> <> .
9802---
9803name: varexpand-null-3
9804description:
9805	Ensure concatenating behaviour matches other shells
9806stdin:
9807	showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
9808	showargs 0 ""$@
9809	x=; showargs 1 "$x"$@
9810	set A; showargs 2 "${@:+}"
9811	n() { echo "$#"; }
9812	unset e
9813	set -- a b
9814	n """$@"
9815	n "$@"
9816	n "$@"""
9817	n "$e""$@"
9818	n "$@"
9819	n "$@""$e"
9820	set --
9821	n """$@"
9822	n "$@"
9823	n "$@"""
9824	n "$e""$@"
9825	n "$@"
9826	n "$@""$e"
9827expected-stdout:
9828	<0> <> .
9829	<1> <> .
9830	<2> <> .
9831	2
9832	2
9833	2
9834	2
9835	2
9836	2
9837	1
9838	0
9839	1
9840	1
9841	0
9842	1
9843---
9844name: varexpand-funny-chars
9845description:
9846	Check some characters
9847	XXX \uEF80 is asymmetric, possibly buggy so we don’t check this
9848stdin:
9849	x=$'<\x00>'; typeset -p x
9850	x=$'<\x01>'; typeset -p x
9851	x=$'<\u0000>'; typeset -p x
9852	x=$'<\u0001>'; typeset -p x
9853expected-stdout:
9854	typeset x='<'
9855	typeset x=$'<\001>'
9856	typeset x='<'
9857	typeset x=$'<\001>'
9858---
9859name: print-funny-chars
9860description:
9861	Check print builtin's capability to output designated characters
9862stdin:
9863	{
9864		print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>'
9865		print '<\x00>'
9866		print '<\x01>'
9867		print '<\u0000>'
9868		print '<\u0001>'
9869	} | {
9870		# integer-base-one-3Ar
9871		typeset -Uui16 -Z11 pos=0
9872		typeset -Uui16 -Z5 hv=2147483647
9873		dasc=
9874		if read -arN -1 line; then
9875			typeset -i1 line
9876			i=0
9877			while (( i < ${#line[*]} )); do
9878				hv=${line[i++]}
9879				if (( (pos & 15) == 0 )); then
9880					(( pos )) && print -r -- "$dasc|"
9881					print -n "${pos#16#}  "
9882					dasc=' |'
9883				fi
9884				print -n "${hv#16#} "
9885				if (( (hv < 32) || (hv > 126) )); then
9886					dasc=$dasc.
9887				else
9888					dasc=$dasc${line[i-1]#1#}
9889				fi
9890				(( (pos++ & 15) == 7 )) && print -n -- '- '
9891			done
9892		fi
9893		while (( pos & 15 )); do
9894			print -n '   '
9895			(( (pos++ & 15) == 7 )) && print -n -- '- '
9896		done
9897		(( hv == 2147483647 )) || print -r -- "$dasc|"
9898	}
9899expected-stdout:
9900	00000000  3C 64 E4 DB C3 9B E2 82 - AC C3 9B 40 3E 0A 3C 00  |<d.........@>.<.|
9901	00000010  3E 0A 3C 01 3E 0A 3C 00 - 3E 0A 3C 01 3E 0A        |>.<.>.<.>.<.>.|
9902---
9903name: print-bksl-c
9904description:
9905	Check print builtin's \c escape
9906stdin:
9907	print '\ca'; print b
9908expected-stdout:
9909	ab
9910---
9911name: print-cr
9912description:
9913	Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do
9914stdin:
9915	echo '#!'"$__progname" >foo
9916	cat >>foo <<-'EOF'
9917		print -n -- '220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r\n220->> Bitte keine Werbung einwerfen! <<\r\r\n220 Who do you wanna pretend to be today'
9918		print \?
9919	EOF
9920	chmod +x foo
9921	echo "[$(./foo)]"
9922	./foo | while IFS= read -r line; do
9923		print -r -- "{$line}"
9924	done
9925expected-stdout:
9926	[220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT
9927	220->> Bitte keine Werbung einwerfen! <<
9928
9929	220 Who do you wanna pretend to be today?
9930]
9931	{220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT
9932}
9933	{220->> Bitte keine Werbung einwerfen! <<
9934
9935}
9936	{220 Who do you wanna pretend to be today?
9937}
9938---
9939name: print-crlf
9940description:
9941	Check that CR+LF is shown and read as-is
9942category: shell:textmode-no
9943stdin:
9944	cat >foo <<-'EOF'
9945		x='bar
9946		' #
9947		echo .${#x} #
9948		if test x"$KSH_VERSION" = x""; then #
9949			printf '<%s>' "$x" #
9950		else #
9951			print -nr -- "<$x>" #
9952		fi #
9953	EOF
9954	echo "[$("$__progname" foo)]"
9955	"$__progname" foo | while IFS= read -r line; do
9956		print -r -- "{$line}"
9957	done
9958expected-stdout:
9959	[.5
9960	<bar
9961	>]
9962	{.5}
9963	{<bar
9964}
9965---
9966name: print-crlf-textmode
9967description:
9968	Check that CR+LF is treated as newline
9969category: shell:textmode-yes
9970stdin:
9971	cat >foo <<-'EOF'
9972		x='bar
9973		' #
9974		echo .${#x} #
9975		if test x"$KSH_VERSION" = x""; then #
9976			printf '<%s>' "$x" #
9977		else #
9978			print -nr -- "<$x>" #
9979		fi #
9980	EOF
9981	echo "[$("$__progname" foo)]"
9982	"$__progname" foo | while IFS= read -r line; do
9983		print -r -- "{$line}"
9984	done
9985expected-stdout:
9986	[.4
9987	<bar
9988	>]
9989	{.4}
9990	{<bar}
9991---
9992name: print-lf
9993description:
9994	Check that LF-only is shown and read as-is
9995stdin:
9996	cat >foo <<-'EOF'
9997		x='bar
9998		' #
9999		echo .${#x} #
10000		if test x"$KSH_VERSION" = x""; then #
10001			printf '<%s>' "$x" #
10002		else #
10003			print -nr -- "<$x>" #
10004		fi #
10005	EOF
10006	echo "[$("$__progname" foo)]"
10007	"$__progname" foo | while IFS= read -r line; do
10008		print -r -- "{$line}"
10009	done
10010expected-stdout:
10011	[.4
10012	<bar
10013	>]
10014	{.4}
10015	{<bar}
10016---
10017name: print-nul-chars
10018description:
10019	Check handling of NUL characters for print and COMSUB
10020stdin:
10021	x=$(print '<\0>')
10022	print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \
10023	    ${#x} "$x" '<\0>'
10024expected-stdout-pattern:
10025	/^4 3 2 <> <\0>$/
10026---
10027name: print-array
10028description:
10029	Check that print -A works as expected
10030stdin:
10031	print -An 0x20AC 0xC3 0xBC 8#101
10032	set -U
10033	print -A 0x20AC 0xC3 0xBC 8#102
10034expected-stdout:
10035	�üA€Ã¼B
10036---
10037name: print-escapes
10038description:
10039	Check backslash expansion by the print builtin
10040stdin:
10041	print '\ \!\"\#\$\%\&'\\\''\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8' \
10042	    '\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T' \
10043	    '\U\V\W\X\Y\Z\[\\\]\^\_\`\a\b  \d\e\f\g\h\i\j\k\l\m\n\o\p' \
10044	    '\q\r\s\t\u\v\w\x\y\z\{\|\}\~' '\u20acd' '\U20acd' '\x123' \
10045	    '\0x' '\0123' '\01234' | {
10046		# integer-base-one-3As
10047		typeset -Uui16 -Z11 pos=0
10048		typeset -Uui16 -Z5 hv=2147483647
10049		typeset -i1 wc=0x0A
10050		dasc=
10051		nl=${wc#1#}
10052		while IFS= read -r line; do
10053			line=$line$nl
10054			while [[ -n $line ]]; do
10055				hv=1#${line::1}
10056				if (( (pos & 15) == 0 )); then
10057					(( pos )) && print -r -- "$dasc|"
10058					print -n "${pos#16#}  "
10059					dasc=' |'
10060				fi
10061				print -n "${hv#16#} "
10062				if (( (hv < 32) || (hv > 126) )); then
10063					dasc=$dasc.
10064				else
10065					dasc=$dasc${line::1}
10066				fi
10067				(( (pos++ & 15) == 7 )) && print -n -- '- '
10068				line=${line:1}
10069			done
10070		done
10071		while (( pos & 15 )); do
10072			print -n '   '
10073			(( (pos++ & 15) == 7 )) && print -n -- '- '
10074		done
10075		(( hv == 2147483647 )) || print -r -- "$dasc|"
10076	}
10077expected-stdout:
10078	00000000  5C 20 5C 21 5C 22 5C 23 - 5C 24 5C 25 5C 26 5C 27  |\ \!\"\#\$\%\&\'|
10079	00000010  5C 28 5C 29 5C 2A 5C 2B - 5C 2C 5C 2D 5C 2E 5C 2F  |\(\)\*\+\,\-\.\/|
10080	00000020  5C 31 5C 32 5C 33 5C 34 - 5C 35 5C 36 5C 37 5C 38  |\1\2\3\4\5\6\7\8|
10081	00000030  20 5C 39 5C 3A 5C 3B 5C - 3C 5C 3D 5C 3E 5C 3F 5C  | \9\:\;\<\=\>\?\|
10082	00000040  40 5C 41 5C 42 5C 43 5C - 44 1B 5C 46 5C 47 5C 48  |@\A\B\C\D.\F\G\H|
10083	00000050  5C 49 5C 4A 5C 4B 5C 4C - 5C 4D 5C 4E 5C 4F 5C 50  |\I\J\K\L\M\N\O\P|
10084	00000060  5C 51 5C 52 5C 53 5C 54 - 20 5C 55 5C 56 5C 57 5C  |\Q\R\S\T \U\V\W\|
10085	00000070  58 5C 59 5C 5A 5C 5B 5C - 5C 5D 5C 5E 5C 5F 5C 60  |X\Y\Z\[\\]\^\_\`|
10086	00000080  07 08 20 20 5C 64 1B 0C - 5C 67 5C 68 5C 69 5C 6A  |..  \d..\g\h\i\j|
10087	00000090  5C 6B 5C 6C 5C 6D 0A 5C - 6F 5C 70 20 5C 71 0D 5C  |\k\l\m.\o\p \q.\|
10088	000000A0  73 09 5C 75 0B 5C 77 5C - 78 5C 79 5C 7A 5C 7B 5C  |s.\u.\w\x\y\z\{\|
10089	000000B0  7C 5C 7D 5C 7E 20 E2 82 - AC 64 20 EF BF BD 20 12  ||\}\~ ...d ... .|
10090	000000C0  33 20 78 20 53 20 53 34 - 0A                       |3 x S S4.|
10091---
10092name: dollar-doublequoted-strings
10093description:
10094	Check that a $ preceding "…" is ignored
10095stdin:
10096	echo $"Localise me!"
10097	cat <<<$"Me too!"
10098	V=X
10099	aol=aol
10100	cat <<-$"aol"
10101		I do not take a $V for a V!
10102	aol
10103expected-stdout:
10104	Localise me!
10105	Me too!
10106	I do not take a $V for a V!
10107---
10108name: dollar-quoted-strings
10109description:
10110	Check backslash expansion by $'…' strings
10111stdin:
10112	print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
10113	chmod +x pfn
10114	./pfn $'\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/ \1\2\3\4\5\6' \
10115	    $'a\0b' $'a\01b' $'\7\8\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I' \
10116	    $'\J\K\L\M\N\O\P\Q\R\S\T\U1\V\W\X\Y\Z\[\\\]\^\_\`\a\b\d\e' \
10117	    $'\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u1\v\w\x1\y\z\{\|\}\~ $x' \
10118	    $'\u20acd' $'\U20acd' $'\x123' $'fn\x0rd' $'\0234' $'\234' \
10119	    $'\2345' $'\ca' $'\c!' $'\c?' $'\c…' $'a\
10120	b' | {
10121		# integer-base-one-3As
10122		typeset -Uui16 -Z11 pos=0
10123		typeset -Uui16 -Z5 hv=2147483647
10124		typeset -i1 wc=0x0A
10125		dasc=
10126		nl=${wc#1#}
10127		while IFS= read -r line; do
10128			line=$line$nl
10129			while [[ -n $line ]]; do
10130				hv=1#${line::1}
10131				if (( (pos & 15) == 0 )); then
10132					(( pos )) && print -r -- "$dasc|"
10133					print -n "${pos#16#}  "
10134					dasc=' |'
10135				fi
10136				print -n "${hv#16#} "
10137				if (( (hv < 32) || (hv > 126) )); then
10138					dasc=$dasc.
10139				else
10140					dasc=$dasc${line::1}
10141				fi
10142				(( (pos++ & 15) == 7 )) && print -n -- '- '
10143				line=${line:1}
10144			done
10145		done
10146		while (( pos & 15 )); do
10147			print -n '   '
10148			(( (pos++ & 15) == 7 )) && print -n -- '- '
10149		done
10150		(( hv == 2147483647 )) || print -r -- "$dasc|"
10151	}
10152expected-stdout:
10153	00000000  20 21 22 23 24 25 26 27 - 28 29 2A 2B 2C 2D 2E 2F  | !"#$%&'()*+,-./|
10154	00000010  20 01 02 03 04 05 06 0A - 61 0A 61 01 62 0A 07 38  | .......a.a.b..8|
10155	00000020  39 3A 3B 3C 3D 3E 3F 40 - 41 42 43 44 1B 46 47 48  |9:;<=>?@ABCD.FGH|
10156	00000030  49 0A 4A 4B 4C 4D 4E 4F - 50 51 52 53 54 01 56 57  |I.JKLMNOPQRST.VW|
10157	00000040  58 59 5A 5B 5C 5D 5E 5F - 60 07 08 64 1B 0A 0C 67  |XYZ[\]^_`..d...g|
10158	00000050  68 69 6A 6B 6C 6D 0A 6F - 70 71 0D 73 09 01 0B 77  |hijklm.opq.s...w|
10159	00000060  01 79 7A 7B 7C 7D 7E 20 - 24 78 0A E2 82 AC 64 0A  |.yz{|}~ $x....d.|
10160	00000070  EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C  |.......fn..4....|
10161	00000080  35 0A 01 0A 01 0A 7F 0A - 82 80 A6 0A 61 0A 62 0A  |5...........a.b.|
10162---
10163name: dollar-quotes-in-heredocs-strings
10164description:
10165	They are, however, not parsed in here documents, here strings
10166	(outside of string delimiters) or regular strings, but in
10167	parameter substitutions.
10168stdin:
10169	cat <<EOF
10170		dollar = strchr(s, '$');	/* ' */
10171		foo " bar \" baz
10172	EOF
10173	cat <<$'a\tb'
10174	a\tb
10175	a	b
10176	cat <<<"dollar = strchr(s, '$');	/* ' */"
10177	cat <<<'dollar = strchr(s, '\''$'\'');	/* '\'' */'
10178	x="dollar = strchr(s, '$');	/* ' */"
10179	cat <<<"$x"
10180	cat <<<$'a\E[0m\tb'
10181	unset nl; print -r -- "x${nl:=$'\n'}y"
10182	echo "1 foo\"bar"
10183	# cf & HEREDOC
10184	cat <<EOF
10185	2 foo\"bar
10186	EOF
10187	# probably never reached for here strings?
10188	cat <<<"3 foo\"bar"
10189	cat <<<"4 foo\\\"bar"
10190	cat <<<'5 foo\"bar'
10191	# old scripts use this (e.g. ncurses)
10192	echo "^$"
10193	# make sure this works, outside of quotes
10194	cat <<<'7'$'\t''.'
10195expected-stdout:
10196		dollar = strchr(s, '$');	/* ' */
10197		foo " bar \" baz
10198	a\tb
10199	dollar = strchr(s, '$');	/* ' */
10200	dollar = strchr(s, '$');	/* ' */
10201	dollar = strchr(s, '$');	/* ' */
10202	a	b
10203	x
10204	y
10205	1 foo"bar
10206	2 foo\"bar
10207	3 foo"bar
10208	4 foo\"bar
10209	5 foo\"bar
10210	^$
10211	7	.
10212---
10213name: dot-needs-argument
10214description:
10215	check Debian #415167 solution: '.' without arguments should fail
10216stdin:
10217	"$__progname" -c .
10218	"$__progname" -c source
10219expected-exit: e != 0
10220expected-stderr-pattern:
10221	/\.: missing argument.*\n.*source: missing argument/
10222---
10223name: dot-errorlevel
10224description:
10225	Ensure dot resets $?
10226stdin:
10227	:>dotfile
10228	(exit 42)
10229	. ./dotfile
10230	echo 1 $? .
10231expected-stdout:
10232	1 0 .
10233---
10234name: alias-function-no-conflict
10235description:
10236	make aliases not conflict with function definitions
10237stdin:
10238	# POSIX function can be defined, but alias overrides it
10239	alias foo='echo bar'
10240	foo
10241	foo() {
10242		echo baz
10243	}
10244	foo
10245	unset -f foo
10246	foo 2>/dev/null || echo rab
10247	# alias overrides ksh function
10248	alias korn='echo bar'
10249	korn
10250	function korn {
10251		echo baz
10252	}
10253	korn
10254	# alias temporarily overrides POSIX function
10255	bla() {
10256		echo bfn
10257	}
10258	bla
10259	alias bla='echo bal'
10260	bla
10261	unalias bla
10262	bla
10263expected-stdout:
10264	bar
10265	bar
10266	bar
10267	bar
10268	bar
10269	bfn
10270	bal
10271	bfn
10272---
10273name: bash-function-parens
10274description:
10275	ensure the keyword function is ignored when preceding
10276	POSIX style function declarations (bashism)
10277stdin:
10278	mk() {
10279		echo '#!'"$__progname"
10280		echo "$1 {"
10281		echo '	echo "bar='\''$0'\'\"
10282		echo '}'
10283		print -r -- "${2:-foo}"
10284	}
10285	mk 'function foo' >f-korn
10286	mk 'foo ()' >f-dash
10287	mk 'function foo ()' >f-bash
10288	print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
10289	chmod +x f-*
10290	u=$(./f-argh)
10291	x="korn: $(./f-korn)"; echo "${x/@("$u")/.}"
10292	x="dash: $(./f-dash)"; echo "${x/@("$u")/.}"
10293	x="bash: $(./f-bash)"; echo "${x/@("$u")/.}"
10294expected-stdout:
10295	korn: bar='foo'
10296	dash: bar='./f-dash'
10297	bash: bar='./f-bash'
10298---
10299name: integer-base-one-1
10300description:
10301	check if the use of fake integer base 1 works
10302stdin:
10303	set -U
10304	typeset -Uui16 i0=1#� i1=1#€
10305	typeset -i1 o0a=64
10306	typeset -i1 o1a=0x263A
10307	typeset -Uui1 o0b=0x7E
10308	typeset -Uui1 o1b=0xFDD0
10309	integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
10310	echo "in <$i0> <$i1>"
10311	echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
10312	typeset -Uui1 i0 i1
10313	echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
10314	typeset -Uui16 tv1=1#~ tv2=1# tv3=1#� tv4=1#� tv5=1#� tv6=1#� tv7=1#  tv8=1#€
10315	echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
10316	typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
10317	echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
10318	typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
10319	echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
10320expected-stdout:
10321	in <16#EFEF> <16#20AC>
10322	out <@|~> <☺|﷐>
10323	pass <16#cafe> <1# > <1#…> <1#f> <�|€>
10324	specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80>
10325	specW <~> <> <�> <�> <�> <�> < > <€>
10326	specU <> <�> <﷐>
10327---
10328name: integer-base-one-2a
10329description:
10330	check if the use of fake integer base 1 stops at correct characters
10331stdin:
10332	set -U
10333	integer x=1#foo
10334	echo /$x/
10335expected-stderr-pattern:
10336	/1#foo: unexpected 'oo'/
10337expected-exit: e != 0
10338---
10339name: integer-base-one-2b
10340description:
10341	check if the use of fake integer base 1 stops at correct characters
10342stdin:
10343	set -U
10344	integer x=1#��
10345	echo /$x/
10346expected-stderr-pattern:
10347	/1#��: unexpected '�'/
10348expected-exit: e != 0
10349---
10350name: integer-base-one-2c1
10351description:
10352	check if the use of fake integer base 1 stops at correct characters
10353stdin:
10354	set -U
10355	integer x=1#…
10356	echo /$x/
10357expected-stdout:
10358	/1#…/
10359---
10360name: integer-base-one-2c2
10361description:
10362	check if the use of fake integer base 1 stops at correct characters
10363stdin:
10364	set +U
10365	integer x=1#…
10366	echo /$x/
10367expected-stderr-pattern:
10368	/1#…: unexpected '�'/
10369expected-exit: e != 0
10370---
10371name: integer-base-one-2d1
10372description:
10373	check if the use of fake integer base 1 handles octets okay
10374stdin:
10375	set -U
10376	typeset -i16 x=1#�
10377	echo /$x/	# invalid utf-8
10378expected-stdout:
10379	/16#efff/
10380---
10381name: integer-base-one-2d2
10382description:
10383	check if the use of fake integer base 1 handles octets
10384stdin:
10385	set -U
10386	typeset -i16 x=1#�
10387	echo /$x/	# invalid 2-byte
10388expected-stdout:
10389	/16#efc2/
10390---
10391name: integer-base-one-2d3
10392description:
10393	check if the use of fake integer base 1 handles octets
10394stdin:
10395	set -U
10396	typeset -i16 x=1#�
10397	echo /$x/	# invalid 2-byte
10398expected-stdout:
10399	/16#efef/
10400---
10401name: integer-base-one-2d4
10402description:
10403	check if the use of fake integer base 1 stops at invalid input
10404stdin:
10405	set -U
10406	typeset -i16 x=1#��
10407	echo /$x/	# invalid 3-byte
10408expected-stderr-pattern:
10409	/1#��: unexpected '�'/
10410expected-exit: e != 0
10411---
10412name: integer-base-one-2d5
10413description:
10414	check if the use of fake integer base 1 stops at invalid input
10415stdin:
10416	set -U
10417	typeset -i16 x=1#��
10418	echo /$x/	# non-minimalistic
10419expected-stderr-pattern:
10420	/1#��: unexpected '�'/
10421expected-exit: e != 0
10422---
10423name: integer-base-one-2d6
10424description:
10425	check if the use of fake integer base 1 stops at invalid input
10426stdin:
10427	set -U
10428	typeset -i16 x=1#���
10429	echo /$x/	# non-minimalistic
10430expected-stderr-pattern:
10431	/1#���: unexpected '�'/
10432expected-exit: e != 0
10433---
10434name: integer-base-one-3As
10435description:
10436	some sample code for hexdumping
10437	not NUL safe; input lines must be NL terminated
10438stdin:
10439	{
10440		print 'Hello, World!\\\nこんにちは!'
10441		typeset -Uui16 i=0x100
10442		# change that to 0xFF once we can handle embedded
10443		# NUL characters in strings / here documents
10444		while (( i++ < 0x1FF )); do
10445			print -n "\x${i#16#1}"
10446		done
10447		print '\0z'
10448	} | {
10449		# integer-base-one-3As
10450		typeset -Uui16 -Z11 pos=0
10451		typeset -Uui16 -Z5 hv=2147483647
10452		typeset -i1 wc=0x0A
10453		dasc=
10454		nl=${wc#1#}
10455		while IFS= read -r line; do
10456			line=$line$nl
10457			while [[ -n $line ]]; do
10458				hv=1#${line::1}
10459				if (( (pos & 15) == 0 )); then
10460					(( pos )) && print -r -- "$dasc|"
10461					print -n "${pos#16#}  "
10462					dasc=' |'
10463				fi
10464				print -n "${hv#16#} "
10465				if (( (hv < 32) || (hv > 126) )); then
10466					dasc=$dasc.
10467				else
10468					dasc=$dasc${line::1}
10469				fi
10470				(( (pos++ & 15) == 7 )) && print -n -- '- '
10471				line=${line:1}
10472			done
10473		done
10474		while (( pos & 15 )); do
10475			print -n '   '
10476			(( (pos++ & 15) == 7 )) && print -n -- '- '
10477		done
10478		(( hv == 2147483647 )) || print -r -- "$dasc|"
10479	}
10480expected-stdout:
10481	00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
10482	00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
10483	00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
10484	00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
10485	00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
10486	00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
10487	00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
10488	00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
10489	00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
10490	00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
10491	000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
10492	000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
10493	000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
10494	000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
10495	000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
10496	000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
10497	00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
10498	00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
10499	00000120  FF 7A 0A                -                          |.z.|
10500---
10501name: integer-base-one-3Ws
10502description:
10503	some sample code for hexdumping UCS-2
10504	not NUL safe; input lines must be NL terminated
10505stdin:
10506	set -U
10507	{
10508		print 'Hello, World!\\\nこんにちは!'
10509		typeset -Uui16 i=0x100
10510		# change that to 0xFF once we can handle embedded
10511		# NUL characters in strings / here documents
10512		while (( i++ < 0x1FF )); do
10513			print -n "\u${i#16#1}"
10514		done
10515		print
10516		print \\xff		# invalid utf-8
10517		print \\xc2		# invalid 2-byte
10518		print \\xef\\xbf\\xc0	# invalid 3-byte
10519		print \\xc0\\x80	# non-minimalistic
10520		print \\xe0\\x80\\x80	# non-minimalistic
10521		print '�￾￿'	# end of range
10522		print '\0z'		# embedded NUL
10523	} | {
10524		# integer-base-one-3Ws
10525		typeset -Uui16 -Z11 pos=0
10526		typeset -Uui16 -Z7 hv
10527		typeset -i1 wc=0x0A
10528		typeset -i lpos
10529		dasc=
10530		nl=${wc#1#}
10531		while IFS= read -r line; do
10532			line=$line$nl
10533			lpos=0
10534			while (( lpos < ${#line} )); do
10535				wc=1#${line:(lpos++):1}
10536				if (( (wc < 32) || \
10537				    ((wc > 126) && (wc < 160)) )); then
10538					dch=.
10539				elif (( (wc & 0xFF80) == 0xEF80 )); then
10540					dch=�
10541				else
10542					dch=${wc#1#}
10543				fi
10544				if (( (pos & 7) == 7 )); then
10545					dasc=$dasc$dch
10546					dch=
10547				elif (( (pos & 7) == 0 )); then
10548					(( pos )) && print -r -- "$dasc|"
10549					print -n "${pos#16#}  "
10550					dasc=' |'
10551				fi
10552				let hv=wc
10553				print -n "${hv#16#} "
10554				(( (pos++ & 7) == 3 )) && \
10555				    print -n -- '- '
10556				dasc=$dasc$dch
10557			done
10558		done
10559		while (( pos & 7 )); do
10560			print -n '     '
10561			(( (pos++ & 7) == 3 )) && print -n -- '- '
10562		done
10563		(( hv == 2147483647 )) || print -r -- "$dasc|"
10564	}
10565expected-stdout:
10566	00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
10567	00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
10568	00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
10569	00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
10570	00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
10571	00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
10572	00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
10573	00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
10574	00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
10575	00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
10576	00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
10577	00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
10578	00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
10579	00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
10580	00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
10581	00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
10582	00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
10583	00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
10584	00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
10585	00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
10586	000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
10587	000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
10588	000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
10589	000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
10590	000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
10591	000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
10592	000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
10593	000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
10594	000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
10595	000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
10596	000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
10597	000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
10598	00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
10599	00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
10600	00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
10601	00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
10602	00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
10603	00000128  EFBE EFEF EFBF EFBF - 000A 007A 000A       |����.z.|
10604---
10605name: integer-base-one-3Ar
10606description:
10607	some sample code for hexdumping; NUL and binary safe
10608stdin:
10609	{
10610		print 'Hello, World!\\\nこんにちは!'
10611		typeset -Uui16 i=0x100
10612		# change that to 0xFF once we can handle embedded
10613		# NUL characters in strings / here documents
10614		while (( i++ < 0x1FF )); do
10615			print -n "\x${i#16#1}"
10616		done
10617		print '\0z'
10618	} | {
10619		# integer-base-one-3Ar
10620		typeset -Uui16 -Z11 pos=0
10621		typeset -Uui16 -Z5 hv=2147483647
10622		dasc=
10623		if read -arN -1 line; then
10624			typeset -i1 line
10625			i=0
10626			while (( i < ${#line[*]} )); do
10627				hv=${line[i++]}
10628				if (( (pos & 15) == 0 )); then
10629					(( pos )) && print -r -- "$dasc|"
10630					print -n "${pos#16#}  "
10631					dasc=' |'
10632				fi
10633				print -n "${hv#16#} "
10634				if (( (hv < 32) || (hv > 126) )); then
10635					dasc=$dasc.
10636				else
10637					dasc=$dasc${line[i-1]#1#}
10638				fi
10639				(( (pos++ & 15) == 7 )) && print -n -- '- '
10640			done
10641		fi
10642		while (( pos & 15 )); do
10643			print -n '   '
10644			(( (pos++ & 15) == 7 )) && print -n -- '- '
10645		done
10646		(( hv == 2147483647 )) || print -r -- "$dasc|"
10647	}
10648expected-stdout:
10649	00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
10650	00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
10651	00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
10652	00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
10653	00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
10654	00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
10655	00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
10656	00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
10657	00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
10658	00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
10659	000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
10660	000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
10661	000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
10662	000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
10663	000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
10664	000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
10665	00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
10666	00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
10667	00000120  FF 00 7A 0A             -                          |..z.|
10668---
10669name: integer-base-one-3Wr
10670description:
10671	some sample code for hexdumping UCS-2; NUL and binary safe
10672stdin:
10673	set -U
10674	{
10675		print 'Hello, World!\\\nこんにちは!'
10676		typeset -Uui16 i=0x100
10677		# change that to 0xFF once we can handle embedded
10678		# NUL characters in strings / here documents
10679		while (( i++ < 0x1FF )); do
10680			print -n "\u${i#16#1}"
10681		done
10682		print
10683		print \\xff		# invalid utf-8
10684		print \\xc2		# invalid 2-byte
10685		print \\xef\\xbf\\xc0	# invalid 3-byte
10686		print \\xc0\\x80	# non-minimalistic
10687		print \\xe0\\x80\\x80	# non-minimalistic
10688		print '�￾￿'	# end of range
10689		print '\0z'		# embedded NUL
10690	} | {
10691		# integer-base-one-3Wr
10692		typeset -Uui16 -Z11 pos=0
10693		typeset -Uui16 -Z7 hv=2147483647
10694		dasc=
10695		if read -arN -1 line; then
10696			typeset -i1 line
10697			i=0
10698			while (( i < ${#line[*]} )); do
10699				hv=${line[i++]}
10700				if (( (hv < 32) || \
10701				    ((hv > 126) && (hv < 160)) )); then
10702					dch=.
10703				elif (( (hv & 0xFF80) == 0xEF80 )); then
10704					dch=�
10705				else
10706					dch=${line[i-1]#1#}
10707				fi
10708				if (( (pos & 7) == 7 )); then
10709					dasc=$dasc$dch
10710					dch=
10711				elif (( (pos & 7) == 0 )); then
10712					(( pos )) && print -r -- "$dasc|"
10713					print -n "${pos#16#}  "
10714					dasc=' |'
10715				fi
10716				print -n "${hv#16#} "
10717				(( (pos++ & 7) == 3 )) && \
10718				    print -n -- '- '
10719				dasc=$dasc$dch
10720			done
10721		fi
10722		while (( pos & 7 )); do
10723			print -n '     '
10724			(( (pos++ & 7) == 3 )) && print -n -- '- '
10725		done
10726		(( hv == 2147483647 )) || print -r -- "$dasc|"
10727	}
10728expected-stdout:
10729	00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
10730	00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
10731	00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
10732	00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
10733	00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
10734	00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
10735	00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
10736	00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
10737	00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
10738	00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
10739	00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
10740	00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
10741	00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
10742	00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
10743	00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
10744	00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
10745	00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
10746	00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
10747	00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
10748	00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
10749	000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
10750	000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
10751	000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
10752	000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
10753	000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
10754	000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
10755	000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
10756	000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
10757	000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
10758	000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
10759	000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
10760	000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
10761	00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
10762	00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
10763	00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
10764	00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
10765	00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
10766	00000128  EFBE EFEF EFBF EFBF - 000A 0000 007A 000A  |����..z.|
10767---
10768name: integer-base-one-4
10769description:
10770	Check if ksh93-style base-one integers work
10771category: !smksh
10772stdin:
10773	set -U
10774	echo 1 $(('a'))
10775	(echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/"
10776	echo 3 $(('…'))
10777	x="'a'"
10778	echo "4 <$x>"
10779	echo 5 $(($x))
10780	echo 6 $((x))
10781expected-stdout:
10782	1 97
10783	2p 'aa': multi-character character constant
10784	3 8230
10785	4 <'a'>
10786	5 97
10787	6 97
10788---
10789name: integer-base-one-5A
10790description:
10791	Check to see that we’re NUL and UCS safe
10792category: !shell:ebcdic-yes
10793stdin:
10794	set +U
10795	print 'a\0b\xfdz' >x
10796	read -a y <x
10797	set -U
10798	typeset -Uui16 y
10799	print ${y[*]} .
10800expected-stdout:
10801	16#61 16#0 16#62 16#FD 16#7A .
10802---
10803name: integer-base-one-5E
10804description:
10805	Check to see that we’re NUL and UCS safe
10806category: !shell:ebcdic-no
10807stdin:
10808	set +U
10809	print 'a\0b\xfdz' >x
10810	read -a y <x
10811	set -U
10812	typeset -Uui16 y
10813	print ${y[*]} .
10814expected-stdout:
10815	16#81 16#0 16#82 16#FD 16#A9 .
10816---
10817name: integer-base-one-5W
10818description:
10819	Check to see that we’re NUL and UCS safe
10820stdin:
10821	set -U
10822	print 'a\0b€c' >x
10823	read -a y <x
10824	set +U
10825	typeset -Uui16 y
10826	print ${y[*]} .
10827expected-stdout:
10828	16#61 16#0 16#62 16#20AC 16#63 .
10829---
10830name: ulimit-1
10831description:
10832	Check that ulimit as used in dot.mksh works or is stubbed
10833stdin:
10834	ulimit -c 0
10835---
10836name: ulimit-2
10837description:
10838	Check if we can use a specific syntax idiom for ulimit
10839	XXX Haiku works, but only for -n and -V
10840category: !os:haiku,!os:syllable
10841stdin:
10842	if ! x=$(ulimit -d) || [[ $x = unknown ]]; then
10843		#echo expected to fail on this OS
10844		echo okay
10845	else
10846		ulimit -dS $x && echo okay
10847	fi
10848expected-stdout:
10849	okay
10850---
10851name: redir-1
10852description:
10853	Check some of the most basic invariants of I/O redirection
10854stdin:
10855	i=0
10856	function d {
10857		print o$i.
10858		print -u2 e$((i++)).
10859	}
10860	d >a 2>b
10861	echo =1=
10862	cat a
10863	echo =2=
10864	cat b
10865	echo =3=
10866	d 2>&1 >c
10867	echo =4=
10868	cat c
10869	echo =5=
10870expected-stdout:
10871	=1=
10872	o0.
10873	=2=
10874	e0.
10875	=3=
10876	e1.
10877	=4=
10878	o1.
10879	=5=
10880---
10881name: bashiop-1
10882description:
10883	Check if GNU bash-like I/O redirection works
10884	Part 1: this is also supported by GNU bash
10885stdin:
10886	exec 3>&1
10887	function threeout {
10888		echo ras
10889		echo dwa >&2
10890		echo tri >&3
10891	}
10892	threeout &>foo
10893	echo ===
10894	cat foo
10895expected-stdout:
10896	tri
10897	===
10898	ras
10899	dwa
10900---
10901name: bashiop-2a
10902description:
10903	Check if GNU bash-like I/O redirection works
10904	Part 2: this is *not* supported by GNU bash
10905stdin:
10906	exec 3>&1
10907	function threeout {
10908		echo ras
10909		echo dwa >&2
10910		echo tri >&3
10911	}
10912	threeout 3&>foo
10913	echo ===
10914	cat foo
10915expected-stdout:
10916	ras
10917	===
10918	dwa
10919	tri
10920---
10921name: bashiop-2b
10922description:
10923	Check if GNU bash-like I/O redirection works
10924	Part 2: this is *not* supported by GNU bash
10925stdin:
10926	exec 3>&1
10927	function threeout {
10928		echo ras
10929		echo dwa >&2
10930		echo tri >&3
10931	}
10932	threeout 3>foo &>&3
10933	echo ===
10934	cat foo
10935expected-stdout:
10936	===
10937	ras
10938	dwa
10939	tri
10940---
10941name: bashiop-2c
10942description:
10943	Check if GNU bash-like I/O redirection works
10944	Part 2: this is supported by GNU bash 4 only
10945stdin:
10946	echo mir >foo
10947	set -o noclobber
10948	exec 3>&1
10949	function threeout {
10950		echo ras
10951		echo dwa >&2
10952		echo tri >&3
10953	}
10954	threeout &>>foo
10955	echo ===
10956	cat foo
10957expected-stdout:
10958	tri
10959	===
10960	mir
10961	ras
10962	dwa
10963---
10964name: bashiop-3a
10965description:
10966	Check if GNU bash-like I/O redirection fails correctly
10967	Part 1: this is also supported by GNU bash
10968stdin:
10969	echo mir >foo
10970	set -o noclobber
10971	exec 3>&1
10972	function threeout {
10973		echo ras
10974		echo dwa >&2
10975		echo tri >&3
10976	}
10977	threeout &>foo
10978	echo ===
10979	cat foo
10980expected-stdout:
10981	===
10982	mir
10983expected-stderr-pattern: /.*: can't (create|overwrite) .*/
10984---
10985name: bashiop-3b
10986description:
10987	Check if GNU bash-like I/O redirection fails correctly
10988	Part 2: this is *not* supported by GNU bash
10989stdin:
10990	echo mir >foo
10991	set -o noclobber
10992	exec 3>&1
10993	function threeout {
10994		echo ras
10995		echo dwa >&2
10996		echo tri >&3
10997	}
10998	threeout &>|foo
10999	echo ===
11000	cat foo
11001expected-stdout:
11002	tri
11003	===
11004	ras
11005	dwa
11006---
11007name: bashiop-4
11008description:
11009	Check if GNU bash-like I/O redirection works
11010	Part 4: this is also supported by GNU bash,
11011	but failed in some mksh versions
11012stdin:
11013	exec 3>&1
11014	function threeout {
11015		echo ras
11016		echo dwa >&2
11017		echo tri >&3
11018	}
11019	function blubb {
11020		[[ -e bar ]] && threeout "$bf" &>foo
11021	}
11022	blubb
11023	echo -n >bar
11024	blubb
11025	echo ===
11026	cat foo
11027expected-stdout:
11028	tri
11029	===
11030	ras
11031	dwa
11032---
11033name: bashiop-5
11034description:
11035	Check if GNU bash-like I/O redirection is only supported
11036	in !POSIX !sh mode as it breaks existing scripts' syntax
11037stdin:
11038	:>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
11039	:>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
11040	:>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
11041expected-stdout:
11042	1  = foo echo bar .
11043	2  = bar .
11044	3  = bar .
11045---
11046name: oksh-eval
11047description:
11048	Check expansions.
11049stdin:
11050	a=
11051	for n in ${a#*=}; do echo 1hu ${n} .; done
11052	for n in "${a#*=}"; do echo 1hq ${n} .; done
11053	for n in ${a##*=}; do echo 2hu ${n} .; done
11054	for n in "${a##*=}"; do echo 2hq ${n} .; done
11055	for n in ${a%=*}; do echo 1pu ${n} .; done
11056	for n in "${a%=*}"; do echo 1pq ${n} .; done
11057	for n in ${a%%=*}; do echo 2pu ${n} .; done
11058	for n in "${a%%=*}"; do echo 2pq ${n} .; done
11059expected-stdout:
11060	1hq .
11061	2hq .
11062	1pq .
11063	2pq .
11064---
11065name: oksh-and-list-error-1
11066description:
11067	Test exit status of rightmost element in 2 element && list in -e mode
11068stdin:
11069	true && false
11070	echo "should not print"
11071arguments: !-e!
11072expected-exit: e != 0
11073---
11074name: oksh-and-list-error-2
11075description:
11076	Test exit status of rightmost element in 3 element && list in -e mode
11077stdin:
11078	true && true && false
11079	echo "should not print"
11080arguments: !-e!
11081expected-exit: e != 0
11082---
11083name: oksh-or-list-error-1
11084description:
11085	Test exit status of || list in -e mode
11086stdin:
11087	false || false
11088	echo "should not print"
11089arguments: !-e!
11090expected-exit: e != 0
11091---
11092name: oksh-longline-crash
11093description:
11094	This used to cause a core dump
11095stdin:
11096	ulimit -c 0
11097	deplibs="-lz -lpng /usr/local/lib/libjpeg.la -ltiff -lm -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libglib.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgtk.la -ltiff -ljpeg -lz -lpng -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk_pixbuf.la -lz -lpng /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libglib.la -lm -lm /usr/local/lib/libaudiofile.la -lm -lm -laudiofile -L/usr/local/lib /usr/local/lib/libesd.la -lm -lz -L/usr/local/lib /usr/local/lib/libgnomesupport.la -lm -lz -lm -lglib -L/usr/local/lib /usr/local/lib/libgnome.la -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgtk.la -lICE -lSM -lz -lpng /usr/local/lib/libungif.la /usr/local/lib/libjpeg.la -ltiff -lm -lz -lpng /usr/local/lib/libungif.la -lz /usr/local/lib/libjpeg.la -ltiff -L/usr/local/lib -L/usr/X11R6/lib /usr/local/lib/libgdk_imlib.la -lm -L/usr/local/lib /usr/local/lib/libart_lgpl.la -lm -lz -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lICE -lSM -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -L/usr/X11R6/lib -lm -lz -lpng -lungif -lz -ljpeg -ltiff -ljpeg -lgdk_imlib -lglib -lm -laudiofile -lm -laudiofile -lesd -L/usr/local/lib /usr/local/lib/libgnomeui.la -lz -lz /usr/local/lib/libxml.la -lz -lz -lz /usr/local/lib/libxml.la -lm -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libglib.la /usr/local/lib/libgmodule.la -lintl -lglib -lgmodule /usr/local/lib/libgdk.la /usr/local/lib/libgtk.la -L/usr/X11R6/lib -L/usr/local/lib /usr/local/lib/libglade.la -lz -lz -lz /usr/local/lib/libxml.la /usr/local/lib/libglib.la -lm -lm /usr/local/lib/libaudiofile.la -lm -lm -laudiofile /usr/local/lib/libesd.la -lm -lz /usr/local/lib/libgnomesupport.la -lm -lz -lm -lglib /usr/local/lib/libgnome.la -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -lglib -lgmodule /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -lglib -lgmodule /usr/local/lib/libgtk.la -lICE -lSM -lz -lpng /usr/local/lib/libungif.la /usr/local/lib/libjpeg.la -ltiff -lm -lz -lz /usr/local/lib/libgdk_imlib.la /usr/local/lib/libart_lgpl.la -lm -lz -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lm -lz -lungif -lz -ljpeg -ljpeg -lgdk_imlib -lglib -lm -laudiofile -lm -laudiofile -lesd /usr/local/lib/libgnomeui.la -L/usr/X11R6/lib -L/usr/local/lib /usr/local/lib/libglade-gnome.la /usr/local/lib/libglib.la -lm -lm /usr/local/lib/libaudiofile.la -lm -lm -laudiofile -L/usr/local/lib /usr/local/lib/libesd.la -lm -lz -L/usr/local/lib /usr/local/lib/libgnomesupport.la -lm -lz -lm -lglib -L/usr/local/lib /usr/local/lib/libgnome.la -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgtk.la -lICE -lSM -lz -lpng /usr/local/lib/libungif.la /usr/local/lib/libjpeg.la -ltiff -lm -lz -lpng /usr/local/lib/libungif.la -lz /usr/local/lib/libjpeg.la -ltiff -L/usr/local/lib -L/usr/X11R6/lib /usr/local/lib/libgdk_imlib.la -lm -L/usr/local/lib /usr/local/lib/libart_lgpl.la -lm -lz -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lICE -lSM -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -L/usr/X11R6/lib -lm -lz -lpng -lungif -lz -ljpeg -ltiff -ljpeg -lgdk_imlib -lglib -lm -laudiofile -lm -laudiofile -lesd -L/usr/local/lib /usr/local/lib/libgnomeui.la -L/usr/X11R6/lib -L/usr/local/lib"
11098	specialdeplibs="-lgnomeui -lart_lgpl -lgdk_imlib -ltiff -ljpeg -lungif -lpng -lz -lSM -lICE -lgtk -lgdk -lgmodule -lintl -lXext -lX11 -lgnome -lgnomesupport -lesd -laudiofile -lm -lglib"
11099	for deplib in $deplibs; do
11100		case $deplib in
11101		-L*)
11102			new_libs="$deplib $new_libs"
11103			;;
11104		*)
11105			case " $specialdeplibs " in
11106			*" $deplib "*)
11107				new_libs="$deplib $new_libs";;
11108			esac
11109			;;
11110		esac
11111	done
11112---
11113name: oksh-seterror-1
11114description:
11115	The -e flag should be ignored when executing a compound list
11116	followed by an if statement.
11117stdin:
11118	if true; then false && false; fi
11119	true
11120arguments: !-e!
11121expected-exit: e == 0
11122---
11123name: oksh-seterror-2
11124description:
11125	The -e flag should be ignored when executing a compound list
11126	followed by an if statement.
11127stdin:
11128	if true; then if true; then false && false; fi; fi
11129	true
11130arguments: !-e!
11131expected-exit: e == 0
11132---
11133name: oksh-seterror-3
11134description:
11135	The -e flag should be ignored when executing a compound list
11136	followed by an elif statement.
11137stdin:
11138	if true; then :; elif true; then false && false; fi
11139arguments: !-e!
11140expected-exit: e == 0
11141---
11142name: oksh-seterror-4
11143description:
11144	The -e flag should be ignored when executing a pipeline
11145	beginning with '!'
11146stdin:
11147	for i in 1 2 3
11148	do
11149		false && false
11150		true || false
11151	done
11152arguments: !-e!
11153expected-exit: e == 0
11154---
11155name: oksh-seterror-5
11156description:
11157	The -e flag should be ignored when executing a pipeline
11158	beginning with '!'
11159stdin:
11160	! true | false
11161	true
11162arguments: !-e!
11163expected-exit: e == 0
11164---
11165name: oksh-seterror-6
11166description:
11167	When trapping ERR and EXIT, both traps should run in -e mode
11168	when an error occurs.
11169stdin:
11170	trap 'echo EXIT' EXIT
11171	trap 'echo ERR' ERR
11172	set -e
11173	false
11174	echo DONE
11175	exit 0
11176arguments: !-e!
11177expected-exit: e != 0
11178expected-stdout:
11179	ERR
11180	EXIT
11181---
11182name: oksh-seterror-7
11183description:
11184	The -e flag within a command substitution should be honored
11185stdin:
11186	echo $( set -e; false; echo foo )
11187arguments: !-e!
11188expected-stdout:
11189
11190---
11191name: oksh-input-comsub
11192description:
11193	A command substitution using input redirection should exit with
11194	failure if the input file does not exist.
11195stdin:
11196	var=$(< non-existent)
11197expected-exit: e != 0
11198expected-stderr-pattern: /non-existent/
11199---
11200name: oksh-empty-for-list
11201description:
11202	A for list which expands to zero items should not execute the body.
11203stdin:
11204	set foo bar baz ; for out in ; do echo $out ; done
11205---
11206name: oksh-varfunction-mod1
11207description:
11208	(Inspired by PR 2450 on OpenBSD.) Calling
11209		FOO=bar f
11210	where f is a ksh style function, should not set FOO in the current
11211	env. If f is a Bourne style function, FOO should be set. Furthermore,
11212	the function should receive a correct value of FOO. However, differing
11213	from oksh, setting FOO in the function itself must change the value in
11214	setting FOO in the function itself should not change the value in
11215	global environment.
11216stdin:
11217	print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
11218	    'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
11219	    done >env; chmod +x env; PATH=.$PATHSEP$PATH
11220	function k {
11221		if [ x$FOO != xbar ]; then
11222			echo 1
11223			return 1
11224		fi
11225		x=$(env | grep FOO)
11226		if [ "x$x" != "xFOO=bar" ]; then
11227			echo 2
11228			return 1;
11229		fi
11230		FOO=foo
11231		return 0
11232	}
11233	b () {
11234		if [ x$FOO != xbar ]; then
11235			echo 3
11236			return 1
11237		fi
11238		x=$(env | grep FOO)
11239		if [ "x$x" != "xFOO=bar" ]; then
11240			echo 4
11241			return 1;
11242		fi
11243		FOO=foo
11244		return 0
11245	}
11246	FOO=bar k
11247	if [ $? != 0 ]; then
11248		exit 1
11249	fi
11250	if [ x$FOO != x ]; then
11251		exit 1
11252	fi
11253	FOO=bar b
11254	if [ $? != 0 ]; then
11255		exit 1
11256	fi
11257	if [ x$FOO != xfoo ]; then
11258		exit 1
11259	fi
11260	FOO=barbar
11261	FOO=bar k
11262	if [ $? != 0 ]; then
11263		exit 1
11264	fi
11265	if [ x$FOO != xbarbar ]; then
11266		exit 1
11267	fi
11268	FOO=bar b
11269	if [ $? != 0 ]; then
11270		exit 1
11271	fi
11272	if [ x$FOO != xfoo ]; then
11273		exit 1
11274	fi
11275---
11276name: fd-cloexec-1
11277description:
11278	Verify that file descriptors > 2 are private for Korn shells
11279	AT&T ksh93 does this still, which means we must keep it as well
11280	XXX fails on some old Perl installations
11281need-pass: no
11282stdin:
11283	cat >cld <<-EOF
11284		#!$__perlname
11285		open(my \$fh, ">&", 9) or die "E: open \$!";
11286		syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
11287	EOF
11288	chmod +x cld
11289	exec 9>&1
11290	./cld
11291expected-exit: e != 0
11292expected-stderr-pattern:
11293	/E: open /
11294---
11295name: fd-cloexec-2
11296description:
11297	Verify that file descriptors > 2 are not private for POSIX shells
11298	See Debian Bug #154540, Closes: #499139
11299	XXX fails on some old Perl installations
11300need-pass: no
11301stdin:
11302	cat >cld <<-EOF
11303		#!$__perlname
11304		open(my \$fh, ">&", 9) or die "E: open \$!";
11305		syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
11306	EOF
11307	chmod +x cld
11308	test -n "$POSH_VERSION" || set -o posix
11309	exec 9>&1
11310	./cld
11311expected-stdout:
11312	Fowl
11313---
11314name: fd-cloexec-3
11315description:
11316	Another check for close-on-exec
11317stdin:
11318	print '#!'"$__progname" >ts
11319	cat >>ts <<'EOF'
11320	s=ERR
11321	read -rN-1 -u$1 s 2>/dev/null; e=$?
11322	print -r -- "($1, $((!e)), $s)"
11323	EOF
11324	chmod +x ts
11325	print foo >tx
11326	runtest() {
11327		s=$1; shift
11328		print -r -- $("$__progname" "$@" -c "$s") "$@" .
11329	}
11330	runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3'
11331	runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3' -o posix
11332	runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3' -o sh
11333	runtest 'exec 3<tx; ./ts 4 4<&3; ./ts 4 4<&3'
11334	runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3 3<&3'
11335expected-stdout:
11336	(3, 1, foo) (3, 0, ERR) .
11337	(3, 1, foo) (3, 1, ) -o posix .
11338	(3, 1, foo) (3, 1, ) -o sh .
11339	(4, 1, foo) (4, 1, ) .
11340	(3, 1, foo) (3, 1, ) .
11341---
11342name: comsub-1a
11343description:
11344	COMSUB are now parsed recursively, so this works
11345	see also regression-6: matching parenthesēs bug
11346	Fails on: pdksh bash2 bash3 zsh
11347	Passes on: bash4 ksh93 mksh(20110313+)
11348stdin:
11349	echo 1 $(case 1 in (1) echo yes;; (2) echo no;; esac) .
11350	echo 2 $(case 1 in 1) echo yes;; 2) echo no;; esac) .
11351	TEST=1234; echo 3 ${TEST: $(case 1 in (1) echo 1;; (*) echo 2;; esac)} .
11352	TEST=5678; echo 4 ${TEST: $(case 1 in 1) echo 1;; *) echo 2;; esac)} .
11353	a=($(case 1 in (1) echo 1;; (*) echo 2;; esac)); echo 5 ${a[0]} .
11354	a=($(case 1 in 1) echo 1;; *) echo 2;; esac)); echo 6 ${a[0]} .
11355expected-stdout:
11356	1 yes .
11357	2 yes .
11358	3 234 .
11359	4 678 .
11360	5 1 .
11361	6 1 .
11362---
11363name: comsub-1b
11364description:
11365	COMSUB are now parsed recursively, so this works
11366	Fails on: pdksh bash2 bash3 bash4 zsh
11367	Passes on: ksh93 mksh(20110313+)
11368stdin:
11369	echo 1 $(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10)) .
11370	echo 2 $(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20)) .
11371	(( a = $(case 1 in (1) echo 1;; (*) echo 2;; esac) )); echo 3 $a .
11372	(( a = $(case 1 in 1) echo 1;; *) echo 2;; esac) )); echo 4 $a .
11373	a=($(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10))); echo 5 ${a[0]} .
11374	a=($(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20))); echo 6 ${a[0]} .
11375expected-stdout:
11376	1 11 .
11377	2 21 .
11378	3 1 .
11379	4 1 .
11380	5 11 .
11381	6 21 .
11382---
11383name: comsub-2
11384description:
11385	RedHat BZ#496791 – another case of missing recursion
11386	in parsing COMSUB expressions
11387	Fails on: pdksh bash2 bash3¹ bash4¹ zsh
11388	Passes on: ksh93 mksh(20110305+)
11389	① bash[34] seem to choke on comment ending with backslash-newline
11390stdin:
11391	# a comment with " ' \
11392	x=$(
11393	echo yes
11394	# a comment with " ' \
11395	)
11396	echo $x
11397expected-stdout:
11398	yes
11399---
11400name: comsub-3
11401description:
11402	Extended test for COMSUB explaining why a recursive parser
11403	is a must (a non-recursive parser cannot pass all three of
11404	these test cases, especially the ‘#’ is difficult)
11405stdin:
11406	print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.$PATHSEP$PATH
11407	echo $(typeset -i10 x=16#20; echo $x)
11408	echo $(typeset -Uui16 x=16#$(id -u)
11409	) .
11410	echo $(c=1; d=1
11411	typeset -Uui16 a=36#foo; c=2
11412	typeset -Uui16 b=36 #foo; d=2
11413	echo $a $b $c $d)
11414expected-stdout:
11415	32
11416	.
11417	16#4F68 16#24 2 1
11418---
11419name: comsub-4
11420description:
11421	Check the tree dump functions for !MKSH_SMALL functionality
11422category: !smksh
11423stdin:
11424	x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; }
11425	typeset -f x
11426expected-stdout:
11427	x() {
11428		case $1 in
11429		(u)
11430			\echo x
11431			;|
11432		(*)
11433			\echo $1
11434			;;
11435		esac
11436	}
11437---
11438name: comsub-5
11439description:
11440	Check COMSUB works with aliases (does not expand them twice)
11441	and reentrancy safety
11442stdin:
11443	print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
11444	chmod +x pfn
11445	alias echo='echo a'
11446	foo() {
11447		echo moo
11448		./pfn "$(echo foo)"
11449	}
11450	./pfn "$(echo b)"
11451	typeset -f foo >x
11452	cat x
11453	foo
11454	. ./x
11455	typeset -f foo
11456	foo
11457expected-stdout:
11458	a b
11459	foo() {
11460		\echo a moo
11461		./pfn "$(\echo a foo )"
11462	}
11463	a moo
11464	a foo
11465	foo() {
11466		\echo a moo
11467		./pfn "$(\echo a foo )"
11468	}
11469	a moo
11470	a foo
11471---
11472name: comsub-torture
11473description:
11474	Check the tree dump functions work correctly
11475stdin:
11476	if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
11477	while IFS= read -r line; do
11478		if [[ $line = '#1' ]]; then
11479			lastf=0
11480			continue
11481		elif [[ $line = EOFN* ]]; then
11482			fbody=$fbody$'\n'$line
11483			continue
11484		elif [[ $line != '#'* ]]; then
11485			fbody=$fbody$'\n\t'$line
11486			continue
11487		fi
11488		if (( lastf )); then
11489			x="inline_${nextf}() {"$fbody$'\n}\n'
11490			print -nr -- "$x"
11491			print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
11492			x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
11493			print -nr -- "$x"
11494			print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
11495			x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
11496			print -nr -- "$x"
11497			print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
11498		fi
11499		lastf=1
11500		fbody=
11501		nextf=${line#?}
11502	done <<'EOD'
11503	#1
11504	#TCOM
11505	vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
11506	#TPAREN_TPIPE_TLIST
11507	(echo $foo  |  tr -dc 0-9; echo)
11508	#TAND_TOR
11509	cmd  &&  echo ja  ||  echo nein
11510	#TSELECT
11511	select  file  in  *;  do  echo  "<$file>" ;  break ;  done
11512	#TFOR_TTIME
11513	time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
11514	#TCASE
11515	case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
11516	#TIF_TBANG_TDBRACKET_TELIF
11517	if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
11518	#TWHILE
11519	i=1; while (( i < 10 )); do echo $i; let ++i; done
11520	#TUNTIL
11521	i=10; until  (( !--i )) ; do echo $i; done
11522	#TCOPROC
11523	cat  *  |&  ls
11524	#TFUNCT_TBRACE_TASYNC
11525	function  korn  {  echo eins; echo zwei ;  }
11526	bourne  ()  {  logger *  &  }
11527	#IOREAD_IOCAT
11528	tr  x  u  0<foo  >>bar
11529	#IOWRITE_IOCLOB_IOHERE_noIOSKIP
11530	cat  >|bar  <<'EOFN'
11531	foo
11532	EOFN
11533	#IOWRITE_noIOCLOB_IOHERE_IOSKIP
11534	cat  1>bar  <<-EOFI
11535	foo
11536	EOFI
11537	#IORDWR_IODUP
11538	sh  1<>/dev/console  0<&1  2>&1
11539	#COMSUB_EXPRSUB_FUNSUB_VALSUB
11540	echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11541	#QCHAR_OQUOTE_CQUOTE
11542	echo fo\ob\"a\`r\'b\$az
11543	echo "fo\ob\"a\`r\'b\$az"
11544	echo 'fo\ob\"a\`r'\''b\$az'
11545	#OSUBST_CSUBST_OPAT_SPAT_CPAT
11546	[[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11547	#heredoc_closed
11548	x=$(cat <<EOFN
11549	note there must be no space between EOFN and )
11550	EOFN); echo $x
11551	#heredoc_space
11552	x=$(cat <<EOFN\
11553	note the space between EOFN and ) is actually part of the here document marker
11554	EOFN ); echo $x
11555	#patch_motd
11556	x=$(sysctl -n kern.version | sed 1q)
11557	[[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11558	    ed -s /etc/motd 2>&1 <<-EOF
11559		1,/^\$/d
11560		0a
11561			$x
11562
11563		.
11564		wq
11565	EOF)" = @(?) ]] && rm -f /etc/motd
11566	if [[ ! -s /etc/motd ]]; then
11567		install -c -o root -g wheel -m 664 /dev/null /etc/motd
11568		print -- "$x\n" >/etc/motd
11569	fi
11570	#wdarrassign
11571	case x in
11572	x) a+=b; c+=(d e)
11573	esac
11574	#0
11575	EOD
11576expected-stdout:
11577	inline_TCOM() {
11578		vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
11579	}
11580	inline_TCOM() {
11581		vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4"
11582	}
11583	function comsub_TCOM { x=$(
11584		vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
11585	); }
11586	function comsub_TCOM {
11587		x=$(vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4" )
11588	}
11589	function reread_TCOM { x=$((
11590		vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
11591	)|tr u x); }
11592	function reread_TCOM {
11593		x=$( ( vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4" ) | \tr u x )
11594	}
11595	inline_TPAREN_TPIPE_TLIST() {
11596		(echo $foo  |  tr -dc 0-9; echo)
11597	}
11598	inline_TPAREN_TPIPE_TLIST() {
11599		( \echo $foo | \tr -dc 0-9
11600		  \echo )
11601	}
11602	function comsub_TPAREN_TPIPE_TLIST { x=$(
11603		(echo $foo  |  tr -dc 0-9; echo)
11604	); }
11605	function comsub_TPAREN_TPIPE_TLIST {
11606		x=$( ( \echo $foo | \tr -dc 0-9 ; \echo ) )
11607	}
11608	function reread_TPAREN_TPIPE_TLIST { x=$((
11609		(echo $foo  |  tr -dc 0-9; echo)
11610	)|tr u x); }
11611	function reread_TPAREN_TPIPE_TLIST {
11612		x=$( ( ( \echo $foo | \tr -dc 0-9 ; \echo ) ) | \tr u x )
11613	}
11614	inline_TAND_TOR() {
11615		cmd  &&  echo ja  ||  echo nein
11616	}
11617	inline_TAND_TOR() {
11618		\cmd && \echo ja || \echo nein
11619	}
11620	function comsub_TAND_TOR { x=$(
11621		cmd  &&  echo ja  ||  echo nein
11622	); }
11623	function comsub_TAND_TOR {
11624		x=$(\cmd && \echo ja || \echo nein )
11625	}
11626	function reread_TAND_TOR { x=$((
11627		cmd  &&  echo ja  ||  echo nein
11628	)|tr u x); }
11629	function reread_TAND_TOR {
11630		x=$( ( \cmd && \echo ja || \echo nein ) | \tr u x )
11631	}
11632	inline_TSELECT() {
11633		select  file  in  *;  do  echo  "<$file>" ;  break ;  done
11634	}
11635	inline_TSELECT() {
11636		select file in *
11637		do
11638			\echo "<$file>"
11639			\break
11640		done
11641	}
11642	function comsub_TSELECT { x=$(
11643		select  file  in  *;  do  echo  "<$file>" ;  break ;  done
11644	); }
11645	function comsub_TSELECT {
11646		x=$(select file in * ; do \echo "<$file>" ; \break ; done )
11647	}
11648	function reread_TSELECT { x=$((
11649		select  file  in  *;  do  echo  "<$file>" ;  break ;  done
11650	)|tr u x); }
11651	function reread_TSELECT {
11652		x=$( ( select file in * ; do \echo "<$file>" ; \break ; done ) | \tr u x )
11653	}
11654	inline_TFOR_TTIME() {
11655		time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
11656	}
11657	inline_TFOR_TTIME() {
11658		time for i in {1,2,3}
11659		do
11660			\echo $i
11661		done
11662	}
11663	function comsub_TFOR_TTIME { x=$(
11664		time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
11665	); }
11666	function comsub_TFOR_TTIME {
11667		x=$(time for i in {1,2,3} ; do \echo $i ; done )
11668	}
11669	function reread_TFOR_TTIME { x=$((
11670		time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
11671	)|tr u x); }
11672	function reread_TFOR_TTIME {
11673		x=$( ( time for i in {1,2,3} ; do \echo $i ; done ) | \tr u x )
11674	}
11675	inline_TCASE() {
11676		case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
11677	}
11678	inline_TCASE() {
11679		case $foo in
11680		(1)
11681			\echo eins
11682			;&
11683		(2)
11684			\echo zwei
11685			;|
11686		(*)
11687			\echo kann net bis drei zählen
11688			;;
11689		esac
11690	}
11691	function comsub_TCASE { x=$(
11692		case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
11693	); }
11694	function comsub_TCASE {
11695		x=$(case $foo in (1) \echo eins  ;& (2) \echo zwei  ;| (*) \echo kann net bis drei zählen  ;; esac )
11696	}
11697	function reread_TCASE { x=$((
11698		case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
11699	)|tr u x); }
11700	function reread_TCASE {
11701		x=$( ( case $foo in (1) \echo eins  ;& (2) \echo zwei  ;| (*) \echo kann net bis drei zählen  ;; esac ) | \tr u x )
11702	}
11703	inline_TIF_TBANG_TDBRACKET_TELIF() {
11704		if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
11705	}
11706	inline_TIF_TBANG_TDBRACKET_TELIF() {
11707		if ! [[ 1 = 1 ]]
11708		then
11709			\echo eins
11710		elif [[ 1 = 2 ]]
11711		then
11712			\echo zwei
11713		else
11714			\echo drei
11715		fi
11716	}
11717	function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
11718		if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
11719	); }
11720	function comsub_TIF_TBANG_TDBRACKET_TELIF {
11721		x=$(if ! [[ 1 = 1 ]] ; then \echo eins ; elif [[ 1 = 2 ]] ; then \echo zwei ; else \echo drei ; fi )
11722	}
11723	function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
11724		if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
11725	)|tr u x); }
11726	function reread_TIF_TBANG_TDBRACKET_TELIF {
11727		x=$( ( if ! [[ 1 = 1 ]] ; then \echo eins ; elif [[ 1 = 2 ]] ; then \echo zwei ; else \echo drei ; fi ) | \tr u x )
11728	}
11729	inline_TWHILE() {
11730		i=1; while (( i < 10 )); do echo $i; let ++i; done
11731	}
11732	inline_TWHILE() {
11733		i=1
11734		while {
11735			      \\builtin let " i < 10 "
11736		      }
11737		do
11738			\echo $i
11739			\let ++i
11740		done
11741	}
11742	function comsub_TWHILE { x=$(
11743		i=1; while (( i < 10 )); do echo $i; let ++i; done
11744	); }
11745	function comsub_TWHILE {
11746		x=$(i=1 ; while { \\builtin let " i < 10 " ; } ; do \echo $i ; \let ++i ; done )
11747	}
11748	function reread_TWHILE { x=$((
11749		i=1; while (( i < 10 )); do echo $i; let ++i; done
11750	)|tr u x); }
11751	function reread_TWHILE {
11752		x=$( ( i=1 ; while { \\builtin let " i < 10 " ; } ; do \echo $i ; \let ++i ; done ) | \tr u x )
11753	}
11754	inline_TUNTIL() {
11755		i=10; until  (( !--i )) ; do echo $i; done
11756	}
11757	inline_TUNTIL() {
11758		i=10
11759		until {
11760			      \\builtin let " !--i "
11761		      }
11762		do
11763			\echo $i
11764		done
11765	}
11766	function comsub_TUNTIL { x=$(
11767		i=10; until  (( !--i )) ; do echo $i; done
11768	); }
11769	function comsub_TUNTIL {
11770		x=$(i=10 ; until { \\builtin let " !--i " ; } ; do \echo $i ; done )
11771	}
11772	function reread_TUNTIL { x=$((
11773		i=10; until  (( !--i )) ; do echo $i; done
11774	)|tr u x); }
11775	function reread_TUNTIL {
11776		x=$( ( i=10 ; until { \\builtin let " !--i " ; } ; do \echo $i ; done ) | \tr u x )
11777	}
11778	inline_TCOPROC() {
11779		cat  *  |&  ls
11780	}
11781	inline_TCOPROC() {
11782		\cat * |&
11783		\ls
11784	}
11785	function comsub_TCOPROC { x=$(
11786		cat  *  |&  ls
11787	); }
11788	function comsub_TCOPROC {
11789		x=$(\cat * |&  \ls )
11790	}
11791	function reread_TCOPROC { x=$((
11792		cat  *  |&  ls
11793	)|tr u x); }
11794	function reread_TCOPROC {
11795		x=$( ( \cat * |&  \ls ) | \tr u x )
11796	}
11797	inline_TFUNCT_TBRACE_TASYNC() {
11798		function  korn  {  echo eins; echo zwei ;  }
11799		bourne  ()  {  logger *  &  }
11800	}
11801	inline_TFUNCT_TBRACE_TASYNC() {
11802		function korn {
11803			\echo eins
11804			\echo zwei
11805		}
11806		bourne() {
11807			\logger * &
11808		}
11809	}
11810	function comsub_TFUNCT_TBRACE_TASYNC { x=$(
11811		function  korn  {  echo eins; echo zwei ;  }
11812		bourne  ()  {  logger *  &  }
11813	); }
11814	function comsub_TFUNCT_TBRACE_TASYNC {
11815		x=$(function korn { \echo eins ; \echo zwei ; } ; bourne() { \logger * &  } )
11816	}
11817	function reread_TFUNCT_TBRACE_TASYNC { x=$((
11818		function  korn  {  echo eins; echo zwei ;  }
11819		bourne  ()  {  logger *  &  }
11820	)|tr u x); }
11821	function reread_TFUNCT_TBRACE_TASYNC {
11822		x=$( ( function korn { \echo eins ; \echo zwei ; } ; bourne() { \logger * &  } ) | \tr u x )
11823	}
11824	inline_IOREAD_IOCAT() {
11825		tr  x  u  0<foo  >>bar
11826	}
11827	inline_IOREAD_IOCAT() {
11828		\tr x u <foo >>bar
11829	}
11830	function comsub_IOREAD_IOCAT { x=$(
11831		tr  x  u  0<foo  >>bar
11832	); }
11833	function comsub_IOREAD_IOCAT {
11834		x=$(\tr x u <foo >>bar )
11835	}
11836	function reread_IOREAD_IOCAT { x=$((
11837		tr  x  u  0<foo  >>bar
11838	)|tr u x); }
11839	function reread_IOREAD_IOCAT {
11840		x=$( ( \tr x u <foo >>bar ) | \tr u x )
11841	}
11842	inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
11843		cat  >|bar  <<'EOFN'
11844		foo
11845	EOFN
11846	}
11847	inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
11848		\cat >|bar <<"EOFN"
11849		foo
11850	EOFN
11851
11852	}
11853	function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(
11854		cat  >|bar  <<'EOFN'
11855		foo
11856	EOFN
11857	); }
11858	function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
11859		x=$(\cat >|bar <<"EOFN"
11860		foo
11861	EOFN
11862	)
11863	}
11864	function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$((
11865		cat  >|bar  <<'EOFN'
11866		foo
11867	EOFN
11868	)|tr u x); }
11869	function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
11870		x=$( ( \cat >|bar <<"EOFN"
11871		foo
11872	EOFN
11873	) | \tr u x )
11874	}
11875	inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
11876		cat  1>bar  <<-EOFI
11877		foo
11878		EOFI
11879	}
11880	inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
11881		\cat >bar <<-EOFI
11882	foo
11883	EOFI
11884
11885	}
11886	function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(
11887		cat  1>bar  <<-EOFI
11888		foo
11889		EOFI
11890	); }
11891	function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
11892		x=$(\cat >bar <<-EOFI
11893	foo
11894	EOFI
11895	)
11896	}
11897	function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$((
11898		cat  1>bar  <<-EOFI
11899		foo
11900		EOFI
11901	)|tr u x); }
11902	function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
11903		x=$( ( \cat >bar <<-EOFI
11904	foo
11905	EOFI
11906	) | \tr u x )
11907	}
11908	inline_IORDWR_IODUP() {
11909		sh  1<>/dev/console  0<&1  2>&1
11910	}
11911	inline_IORDWR_IODUP() {
11912		\sh 1<>/dev/console <&1 2>&1
11913	}
11914	function comsub_IORDWR_IODUP { x=$(
11915		sh  1<>/dev/console  0<&1  2>&1
11916	); }
11917	function comsub_IORDWR_IODUP {
11918		x=$(\sh 1<>/dev/console <&1 2>&1 )
11919	}
11920	function reread_IORDWR_IODUP { x=$((
11921		sh  1<>/dev/console  0<&1  2>&1
11922	)|tr u x); }
11923	function reread_IORDWR_IODUP {
11924		x=$( ( \sh 1<>/dev/console <&1 2>&1 ) | \tr u x )
11925	}
11926	inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
11927		echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11928	}
11929	inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
11930		\echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;}
11931	}
11932	function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(
11933		echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11934	); }
11935	function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB {
11936		x=$(\echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;} )
11937	}
11938	function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$((
11939		echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11940	)|tr u x); }
11941	function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB {
11942		x=$( ( \echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;} ) | \tr u x )
11943	}
11944	inline_QCHAR_OQUOTE_CQUOTE() {
11945		echo fo\ob\"a\`r\'b\$az
11946		echo "fo\ob\"a\`r\'b\$az"
11947		echo 'fo\ob\"a\`r'\''b\$az'
11948	}
11949	inline_QCHAR_OQUOTE_CQUOTE() {
11950		\echo fo\ob\"a\`r\'b\$az
11951		\echo "fo\ob\"a\`r\'b\$az"
11952		\echo "fo\\ob\\\"a\\\`r"\'"b\\\$az"
11953	}
11954	function comsub_QCHAR_OQUOTE_CQUOTE { x=$(
11955		echo fo\ob\"a\`r\'b\$az
11956		echo "fo\ob\"a\`r\'b\$az"
11957		echo 'fo\ob\"a\`r'\''b\$az'
11958	); }
11959	function comsub_QCHAR_OQUOTE_CQUOTE {
11960		x=$(\echo fo\ob\"a\`r\'b\$az ; \echo "fo\ob\"a\`r\'b\$az" ; \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" )
11961	}
11962	function reread_QCHAR_OQUOTE_CQUOTE { x=$((
11963		echo fo\ob\"a\`r\'b\$az
11964		echo "fo\ob\"a\`r\'b\$az"
11965		echo 'fo\ob\"a\`r'\''b\$az'
11966	)|tr u x); }
11967	function reread_QCHAR_OQUOTE_CQUOTE {
11968		x=$( ( \echo fo\ob\"a\`r\'b\$az ; \echo "fo\ob\"a\`r\'b\$az" ; \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) | \tr u x )
11969	}
11970	inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11971		[[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11972	}
11973	inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11974		[[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11975	}
11976	function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$(
11977		[[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11978	); }
11979	function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT {
11980		x=$([[ ${foo#bl\(u\)b} = @(bar|baz) ]] )
11981	}
11982	function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$((
11983		[[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11984	)|tr u x); }
11985	function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT {
11986		x=$( ( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | \tr u x )
11987	}
11988	inline_heredoc_closed() {
11989		x=$(cat <<EOFN
11990		note there must be no space between EOFN and )
11991	EOFN); echo $x
11992	}
11993	inline_heredoc_closed() {
11994		x=$(\cat <<EOFN
11995		note there must be no space between EOFN and )
11996	EOFN
11997	)
11998		\echo $x
11999	}
12000	function comsub_heredoc_closed { x=$(
12001		x=$(cat <<EOFN
12002		note there must be no space between EOFN and )
12003	EOFN); echo $x
12004	); }
12005	function comsub_heredoc_closed {
12006		x=$(x=$(\cat <<EOFN
12007		note there must be no space between EOFN and )
12008	EOFN
12009	) ; \echo $x )
12010	}
12011	function reread_heredoc_closed { x=$((
12012		x=$(cat <<EOFN
12013		note there must be no space between EOFN and )
12014	EOFN); echo $x
12015	)|tr u x); }
12016	function reread_heredoc_closed {
12017		x=$( ( x=$(\cat <<EOFN
12018		note there must be no space between EOFN and )
12019	EOFN
12020	) ; \echo $x ) | \tr u x )
12021	}
12022	inline_heredoc_space() {
12023		x=$(cat <<EOFN\
12024		note the space between EOFN and ) is actually part of the here document marker
12025	EOFN ); echo $x
12026	}
12027	inline_heredoc_space() {
12028		x=$(\cat <<EOFN\
12029		note the space between EOFN and ) is actually part of the here document marker
12030	EOFN
12031	)
12032		\echo $x
12033	}
12034	function comsub_heredoc_space { x=$(
12035		x=$(cat <<EOFN\
12036		note the space between EOFN and ) is actually part of the here document marker
12037	EOFN ); echo $x
12038	); }
12039	function comsub_heredoc_space {
12040		x=$(x=$(\cat <<EOFN\
12041		note the space between EOFN and ) is actually part of the here document marker
12042	EOFN
12043	) ; \echo $x )
12044	}
12045	function reread_heredoc_space { x=$((
12046		x=$(cat <<EOFN\
12047		note the space between EOFN and ) is actually part of the here document marker
12048	EOFN ); echo $x
12049	)|tr u x); }
12050	function reread_heredoc_space {
12051		x=$( ( x=$(\cat <<EOFN\
12052		note the space between EOFN and ) is actually part of the here document marker
12053	EOFN
12054	) ; \echo $x ) | \tr u x )
12055	}
12056	inline_patch_motd() {
12057		x=$(sysctl -n kern.version | sed 1q)
12058		[[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
12059		    ed -s /etc/motd 2>&1 <<-EOF
12060			1,/^\$/d
12061			0a
12062				$x
12063
12064			.
12065			wq
12066		EOF)" = @(?) ]] && rm -f /etc/motd
12067		if [[ ! -s /etc/motd ]]; then
12068			install -c -o root -g wheel -m 664 /dev/null /etc/motd
12069			print -- "$x\n" >/etc/motd
12070		fi
12071	}
12072	inline_patch_motd() {
12073		x=$(\sysctl -n kern.version | \sed 1q )
12074		[[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF
12075	1,/^\$/d
12076	0a
12077	$x
12078
12079	.
12080	wq
12081	EOF
12082	)" = @(?) ]] && \rm -f /etc/motd
12083		if [[ ! -s /etc/motd ]]
12084		then
12085			\install -c -o root -g wheel -m 664 /dev/null /etc/motd
12086			\print -- "$x\n" >/etc/motd
12087		fi
12088	}
12089	function comsub_patch_motd { x=$(
12090		x=$(sysctl -n kern.version | sed 1q)
12091		[[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
12092		    ed -s /etc/motd 2>&1 <<-EOF
12093			1,/^\$/d
12094			0a
12095				$x
12096
12097			.
12098			wq
12099		EOF)" = @(?) ]] && rm -f /etc/motd
12100		if [[ ! -s /etc/motd ]]; then
12101			install -c -o root -g wheel -m 664 /dev/null /etc/motd
12102			print -- "$x\n" >/etc/motd
12103		fi
12104	); }
12105	function comsub_patch_motd {
12106		x=$(x=$(\sysctl -n kern.version | \sed 1q ) ; [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF
12107	1,/^\$/d
12108	0a
12109	$x
12110
12111	.
12112	wq
12113	EOF
12114	)" = @(?) ]] && \rm -f /etc/motd ; if [[ ! -s /etc/motd ]] ; then \install -c -o root -g wheel -m 664 /dev/null /etc/motd ; \print -- "$x\n" >/etc/motd ; fi )
12115	}
12116	function reread_patch_motd { x=$((
12117		x=$(sysctl -n kern.version | sed 1q)
12118		[[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
12119		    ed -s /etc/motd 2>&1 <<-EOF
12120			1,/^\$/d
12121			0a
12122				$x
12123
12124			.
12125			wq
12126		EOF)" = @(?) ]] && rm -f /etc/motd
12127		if [[ ! -s /etc/motd ]]; then
12128			install -c -o root -g wheel -m 664 /dev/null /etc/motd
12129			print -- "$x\n" >/etc/motd
12130		fi
12131	)|tr u x); }
12132	function reread_patch_motd {
12133		x=$( ( x=$(\sysctl -n kern.version | \sed 1q ) ; [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF
12134	1,/^\$/d
12135	0a
12136	$x
12137
12138	.
12139	wq
12140	EOF
12141	)" = @(?) ]] && \rm -f /etc/motd ; if [[ ! -s /etc/motd ]] ; then \install -c -o root -g wheel -m 664 /dev/null /etc/motd ; \print -- "$x\n" >/etc/motd ; fi ) | \tr u x )
12142	}
12143	inline_wdarrassign() {
12144		case x in
12145		x) a+=b; c+=(d e)
12146		esac
12147	}
12148	inline_wdarrassign() {
12149		case x in
12150		(x)
12151			a+=b
12152			\\builtin set -A c+ -- d e
12153			;;
12154		esac
12155	}
12156	function comsub_wdarrassign { x=$(
12157		case x in
12158		x) a+=b; c+=(d e)
12159		esac
12160	); }
12161	function comsub_wdarrassign {
12162		x=$(case x in (x) a+=b ; \\builtin set -A c+ -- d e  ;; esac )
12163	}
12164	function reread_wdarrassign { x=$((
12165		case x in
12166		x) a+=b; c+=(d e)
12167		esac
12168	)|tr u x); }
12169	function reread_wdarrassign {
12170		x=$( ( case x in (x) a+=b ; \\builtin set -A c+ -- d e  ;; esac ) | \tr u x )
12171	}
12172---
12173name: comsub-torture-io
12174description:
12175	Check the tree dump functions work correctly with I/O redirection
12176stdin:
12177	if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
12178	while IFS= read -r line; do
12179		if [[ $line = '#1' ]]; then
12180			lastf=0
12181			continue
12182		elif [[ $line = EOFN* ]]; then
12183			fbody=$fbody$'\n'$line
12184			continue
12185		elif [[ $line != '#'* ]]; then
12186			fbody=$fbody$'\n\t'$line
12187			continue
12188		fi
12189		if (( lastf )); then
12190			x="inline_${nextf}() {"$fbody$'\n}\n'
12191			print -nr -- "$x"
12192			print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
12193			x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
12194			print -nr -- "$x"
12195			print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
12196			x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
12197			print -nr -- "$x"
12198			print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
12199		fi
12200		lastf=1
12201		fbody=
12202		nextf=${line#?}
12203	done <<'EOD'
12204	#1
12205	#TCOM
12206	vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
12207	#TPAREN_TPIPE_TLIST
12208	(echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
12209	#TAND_TOR
12210	cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
12211	#TSELECT
12212	select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
12213	#TFOR_TTIME
12214	for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
12215	#TCASE
12216	case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
12217	#TIF_TBANG_TDBRACKET_TELIF
12218	if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
12219	#TWHILE
12220	i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12221	#TUNTIL
12222	i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
12223	#TCOPROC
12224	cat  *  >&3 |&  >&3 ls
12225	#TFUNCT_TBRACE_TASYNC
12226	function  korn  {  echo eins; echo >&3 zwei ;  }
12227	bourne  ()  {  logger *  >&3 &  }
12228	#COMSUB_EXPRSUB
12229	echo $(true >&3) $((1+ 2))
12230	#0
12231	EOD
12232expected-stdout:
12233	inline_TCOM() {
12234		vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
12235	}
12236	inline_TCOM() {
12237		vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4" >&3
12238	}
12239	function comsub_TCOM { x=$(
12240		vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
12241	); }
12242	function comsub_TCOM {
12243		x=$(vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4" >&3 )
12244	}
12245	function reread_TCOM { x=$((
12246		vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
12247	)|tr u x); }
12248	function reread_TCOM {
12249		x=$( ( vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4" >&3 ) | \tr u x )
12250	}
12251	inline_TPAREN_TPIPE_TLIST() {
12252		(echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
12253	}
12254	inline_TPAREN_TPIPE_TLIST() {
12255		( \echo $foo | \tr -dc 0-9 >&3
12256		  \echo >&3 ) >&3
12257	}
12258	function comsub_TPAREN_TPIPE_TLIST { x=$(
12259		(echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
12260	); }
12261	function comsub_TPAREN_TPIPE_TLIST {
12262		x=$( ( \echo $foo | \tr -dc 0-9 >&3 ; \echo >&3 ) >&3 )
12263	}
12264	function reread_TPAREN_TPIPE_TLIST { x=$((
12265		(echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
12266	)|tr u x); }
12267	function reread_TPAREN_TPIPE_TLIST {
12268		x=$( ( ( \echo $foo | \tr -dc 0-9 >&3 ; \echo >&3 ) >&3 ) | \tr u x )
12269	}
12270	inline_TAND_TOR() {
12271		cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
12272	}
12273	inline_TAND_TOR() {
12274		\cmd >&3 && \echo ja >&3 || \echo nein >&3
12275	}
12276	function comsub_TAND_TOR { x=$(
12277		cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
12278	); }
12279	function comsub_TAND_TOR {
12280		x=$(\cmd >&3 && \echo ja >&3 || \echo nein >&3 )
12281	}
12282	function reread_TAND_TOR { x=$((
12283		cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
12284	)|tr u x); }
12285	function reread_TAND_TOR {
12286		x=$( ( \cmd >&3 && \echo ja >&3 || \echo nein >&3 ) | \tr u x )
12287	}
12288	inline_TSELECT() {
12289		select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
12290	}
12291	inline_TSELECT() {
12292		select file in *
12293		do
12294			\echo "<$file>"
12295			\break >&3
12296		done >&3
12297	}
12298	function comsub_TSELECT { x=$(
12299		select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
12300	); }
12301	function comsub_TSELECT {
12302		x=$(select file in * ; do \echo "<$file>" ; \break >&3 ; done >&3 )
12303	}
12304	function reread_TSELECT { x=$((
12305		select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
12306	)|tr u x); }
12307	function reread_TSELECT {
12308		x=$( ( select file in * ; do \echo "<$file>" ; \break >&3 ; done >&3 ) | \tr u x )
12309	}
12310	inline_TFOR_TTIME() {
12311		for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
12312	}
12313	inline_TFOR_TTIME() {
12314		for i in {1,2,3}
12315		do
12316			time \echo $i >&3
12317		done >&3
12318	}
12319	function comsub_TFOR_TTIME { x=$(
12320		for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
12321	); }
12322	function comsub_TFOR_TTIME {
12323		x=$(for i in {1,2,3} ; do time \echo $i >&3 ; done >&3 )
12324	}
12325	function reread_TFOR_TTIME { x=$((
12326		for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
12327	)|tr u x); }
12328	function reread_TFOR_TTIME {
12329		x=$( ( for i in {1,2,3} ; do time \echo $i >&3 ; done >&3 ) | \tr u x )
12330	}
12331	inline_TCASE() {
12332		case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
12333	}
12334	inline_TCASE() {
12335		case $foo in
12336		(1)
12337			\echo eins >&3
12338			;&
12339		(2)
12340			\echo zwei >&3
12341			;|
12342		(*)
12343			\echo kann net bis drei zählen >&3
12344			;;
12345		esac >&3
12346	}
12347	function comsub_TCASE { x=$(
12348		case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
12349	); }
12350	function comsub_TCASE {
12351		x=$(case $foo in (1) \echo eins >&3  ;& (2) \echo zwei >&3  ;| (*) \echo kann net bis drei zählen >&3  ;; esac >&3 )
12352	}
12353	function reread_TCASE { x=$((
12354		case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
12355	)|tr u x); }
12356	function reread_TCASE {
12357		x=$( ( case $foo in (1) \echo eins >&3  ;& (2) \echo zwei >&3  ;| (*) \echo kann net bis drei zählen >&3  ;; esac >&3 ) | \tr u x )
12358	}
12359	inline_TIF_TBANG_TDBRACKET_TELIF() {
12360		if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
12361	}
12362	inline_TIF_TBANG_TDBRACKET_TELIF() {
12363		if ! [[ 1 = 1 ]] >&3
12364		then
12365			\echo eins
12366		elif [[ 1 = 2 ]] >&3
12367		then
12368			\echo zwei
12369		else
12370			\echo drei
12371		fi >&3
12372	}
12373	function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
12374		if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
12375	); }
12376	function comsub_TIF_TBANG_TDBRACKET_TELIF {
12377		x=$(if ! [[ 1 = 1 ]] >&3 ; then \echo eins ; elif [[ 1 = 2 ]] >&3 ; then \echo zwei ; else \echo drei ; fi >&3 )
12378	}
12379	function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
12380		if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
12381	)|tr u x); }
12382	function reread_TIF_TBANG_TDBRACKET_TELIF {
12383		x=$( ( if ! [[ 1 = 1 ]] >&3 ; then \echo eins ; elif [[ 1 = 2 ]] >&3 ; then \echo zwei ; else \echo drei ; fi >&3 ) | \tr u x )
12384	}
12385	inline_TWHILE() {
12386		i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12387	}
12388	inline_TWHILE() {
12389		i=1
12390		while {
12391			      \\builtin let " i < 10 "
12392		      } >&3
12393		do
12394			\echo $i
12395			\let ++i
12396		done >&3
12397	}
12398	function comsub_TWHILE { x=$(
12399		i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12400	); }
12401	function comsub_TWHILE {
12402		x=$(i=1 ; while { \\builtin let " i < 10 " ; } >&3 ; do \echo $i ; \let ++i ; done >&3 )
12403	}
12404	function reread_TWHILE { x=$((
12405		i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12406	)|tr u x); }
12407	function reread_TWHILE {
12408		x=$( ( i=1 ; while { \\builtin let " i < 10 " ; } >&3 ; do \echo $i ; \let ++i ; done >&3 ) | \tr u x )
12409	}
12410	inline_TUNTIL() {
12411		i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
12412	}
12413	inline_TUNTIL() {
12414		i=10
12415		until {
12416			      \\builtin let " !--i "
12417		      } >&3
12418		do
12419			\echo $i
12420		done >&3
12421	}
12422	function comsub_TUNTIL { x=$(
12423		i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
12424	); }
12425	function comsub_TUNTIL {
12426		x=$(i=10 ; until { \\builtin let " !--i " ; } >&3 ; do \echo $i ; done >&3 )
12427	}
12428	function reread_TUNTIL { x=$((
12429		i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
12430	)|tr u x); }
12431	function reread_TUNTIL {
12432		x=$( ( i=10 ; until { \\builtin let " !--i " ; } >&3 ; do \echo $i ; done >&3 ) | \tr u x )
12433	}
12434	inline_TCOPROC() {
12435		cat  *  >&3 |&  >&3 ls
12436	}
12437	inline_TCOPROC() {
12438		\cat * >&3 |&
12439		\ls >&3
12440	}
12441	function comsub_TCOPROC { x=$(
12442		cat  *  >&3 |&  >&3 ls
12443	); }
12444	function comsub_TCOPROC {
12445		x=$(\cat * >&3 |&  \ls >&3 )
12446	}
12447	function reread_TCOPROC { x=$((
12448		cat  *  >&3 |&  >&3 ls
12449	)|tr u x); }
12450	function reread_TCOPROC {
12451		x=$( ( \cat * >&3 |&  \ls >&3 ) | \tr u x )
12452	}
12453	inline_TFUNCT_TBRACE_TASYNC() {
12454		function  korn  {  echo eins; echo >&3 zwei ;  }
12455		bourne  ()  {  logger *  >&3 &  }
12456	}
12457	inline_TFUNCT_TBRACE_TASYNC() {
12458		function korn {
12459			\echo eins
12460			\echo zwei >&3
12461		}
12462		bourne() {
12463			\logger * >&3 &
12464		}
12465	}
12466	function comsub_TFUNCT_TBRACE_TASYNC { x=$(
12467		function  korn  {  echo eins; echo >&3 zwei ;  }
12468		bourne  ()  {  logger *  >&3 &  }
12469	); }
12470	function comsub_TFUNCT_TBRACE_TASYNC {
12471		x=$(function korn { \echo eins ; \echo zwei >&3 ; } ; bourne() { \logger * >&3 &  } )
12472	}
12473	function reread_TFUNCT_TBRACE_TASYNC { x=$((
12474		function  korn  {  echo eins; echo >&3 zwei ;  }
12475		bourne  ()  {  logger *  >&3 &  }
12476	)|tr u x); }
12477	function reread_TFUNCT_TBRACE_TASYNC {
12478		x=$( ( function korn { \echo eins ; \echo zwei >&3 ; } ; bourne() { \logger * >&3 &  } ) | \tr u x )
12479	}
12480	inline_COMSUB_EXPRSUB() {
12481		echo $(true >&3) $((1+ 2))
12482	}
12483	inline_COMSUB_EXPRSUB() {
12484		\echo $(\true >&3 ) $((1+ 2))
12485	}
12486	function comsub_COMSUB_EXPRSUB { x=$(
12487		echo $(true >&3) $((1+ 2))
12488	); }
12489	function comsub_COMSUB_EXPRSUB {
12490		x=$(\echo $(\true >&3 ) $((1+ 2)) )
12491	}
12492	function reread_COMSUB_EXPRSUB { x=$((
12493		echo $(true >&3) $((1+ 2))
12494	)|tr u x); }
12495	function reread_COMSUB_EXPRSUB {
12496		x=$( ( \echo $(\true >&3 ) $((1+ 2)) ) | \tr u x )
12497	}
12498---
12499name: funsub-1
12500description:
12501	Check that non-subenvironment command substitution works
12502stdin:
12503	set -e
12504	foo=bar
12505	echo "ob $foo ."
12506	echo "${
12507		echo "ib $foo :"
12508		foo=baz
12509		echo "ia $foo :"
12510		false
12511	}" .
12512	echo "oa $foo ."
12513expected-stdout:
12514	ob bar .
12515	ib bar :
12516	ia baz : .
12517	oa baz .
12518---
12519name: funsub-2
12520description:
12521	You can now reliably use local and return in funsubs
12522	(not exit though)
12523stdin:
12524	x=q; e=1; x=${ echo a; e=2; echo x$e;}; echo 1:y$x,$e,$?.
12525	x=q; e=1; x=${ echo a; typeset e=2; echo x$e;}; echo 2:y$x,$e,$?.
12526	x=q; e=1; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo 3:y$x,$e,$?.
12527expected-stdout:
12528	1:ya x2,2,0.
12529	2:ya x2,1,0.
12530	3:ya,1,3.
12531---
12532name: valsub-1
12533description:
12534	Check that "value substitutions" work as advertised
12535stdin:
12536	x=1
12537	y=2
12538	z=3
12539	REPLY=4
12540	echo "before:	x<$x> y<$y> z<$z> R<$REPLY>"
12541	x=${|
12542		local y
12543		echo "start:	x<$x> y<$y> z<$z> R<$REPLY>"
12544		x=5
12545		y=6
12546		z=7
12547		REPLY=8
12548		echo "end:	x<$x> y<$y> z<$z> R<$REPLY>"
12549	}
12550	echo "after:	x<$x> y<$y> z<$z> R<$REPLY>"
12551	# ensure trailing newlines are kept
12552	t=${|REPLY=$'foo\n\n';}
12553	typeset -p t
12554	echo -n this used to segfault
12555	echo ${|true;}$(true).
12556expected-stdout:
12557	before:	x<1> y<2> z<3> R<4>
12558	start:	x<1> y<> z<3> R<>
12559	end:	x<5> y<6> z<7> R<8>
12560	after:	x<8> y<2> z<7> R<4>
12561	typeset t=$'foo\n\n'
12562	this used to segfault.
12563---
12564name: event-subst-3
12565description:
12566	Check that '!' substitution in noninteractive mode is ignored
12567file-setup: file 755 "falsetto"
12568	#! /bin/sh
12569	echo molto bene
12570	exit 42
12571file-setup: file 755 "!false"
12572	#! /bin/sh
12573	echo si
12574stdin:
12575	export PATH=.$PATHSEP$PATH
12576	falsetto
12577	echo yeap
12578	!false
12579	echo meow
12580	! false
12581	echo = $?
12582	if
12583	! false; then echo foo; else echo bar; fi
12584expected-stdout:
12585	molto bene
12586	yeap
12587	si
12588	meow
12589	= 0
12590	foo
12591---
12592name: event-subst-0
12593description:
12594	Check that '!' substitution in interactive mode is ignored
12595need-ctty: yes
12596arguments: !-i!
12597file-setup: file 755 "falsetto"
12598	#! /bin/sh
12599	echo molto bene
12600	exit 42
12601file-setup: file 755 "!false"
12602	#! /bin/sh
12603	echo si
12604stdin:
12605	export PATH=.$PATHSEP$PATH
12606	falsetto
12607	echo yeap
12608	!false
12609	echo meow
12610	! false
12611	echo = $?
12612	if
12613	! false; then echo foo; else echo bar; fi
12614expected-stdout:
12615	molto bene
12616	yeap
12617	si
12618	meow
12619	= 0
12620	foo
12621expected-stderr-pattern:
12622	/.*/
12623---
12624name: nounset-1
12625description:
12626	Check that "set -u" matches (future) SUSv4 requirement
12627stdin:
12628	(set -u
12629	try() {
12630		local v
12631		eval v=\$$1
12632		if [[ -n $v ]]; then
12633			echo $1=nz
12634		else
12635			echo $1=zf
12636		fi
12637	}
12638	x=y
12639	(echo $x)
12640	echo =1
12641	(echo $y)
12642	echo =2
12643	(try x)
12644	echo =3
12645	(try y)
12646	echo =4
12647	(try 0)
12648	echo =5
12649	(try 2)
12650	echo =6
12651	(try)
12652	echo =7
12653	(echo at=$@)
12654	echo =8
12655	(echo asterisk=$*)
12656	echo =9
12657	(echo $?)
12658	echo =10
12659	(echo $!)
12660	echo =11
12661	(echo $-)
12662	echo =12
12663	#(echo $_)
12664	#echo =13
12665	(echo $#)
12666	echo =14
12667	(mypid=$$; try mypid)
12668	echo =15
12669	) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
12670	exit ${PIPESTATUS[0]}
12671expected-stdout:
12672	y
12673	=1
12674	y: parameter not set
12675	=2
12676	x=nz
12677	=3
12678	y: parameter not set
12679	=4
12680	0=nz
12681	=5
12682	2: parameter not set
12683	=6
12684	1: parameter not set
12685	=7
12686	at=
12687	=8
12688	asterisk=
12689	=9
12690	0
12691	=10
12692	!: parameter not set
12693	=11
12694	ush
12695	=12
12696	0
12697	=14
12698	mypid=nz
12699	=15
12700---
12701name: nameref-1
12702description:
12703	Testsuite for nameref (bound variables)
12704stdin:
12705	bar=global
12706	typeset -n ir2=bar
12707	typeset -n ind=ir2
12708	echo !ind: ${!ind}
12709	echo ind: $ind
12710	echo !ir2: ${!ir2}
12711	echo ir2: $ir2
12712	typeset +n ind
12713	echo !ind: ${!ind}
12714	echo ind: $ind
12715	typeset -n ir2=ind
12716	echo !ir2: ${!ir2}
12717	echo ir2: $ir2
12718	set|grep ^ir2|sed 's/^/s1: /'
12719	typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/'
12720	set -A blub -- e1 e2 e3
12721	typeset -n ind=blub
12722	typeset -n ir2=blub[2]
12723	echo !ind[1]: ${!ind[1]}
12724	echo !ir2: $!ir2
12725	echo ind[1]: ${ind[1]}
12726	echo ir2: $ir2
12727expected-stdout:
12728	!ind: bar
12729	ind: global
12730	!ir2: bar
12731	ir2: global
12732	!ind: ind
12733	ind: ir2
12734	!ir2: ind
12735	ir2: ir2
12736	s1: ir2=ind
12737	s2: typeset -n ir2
12738	!ind[1]: blub[1]
12739	!ir2: ir2
12740	ind[1]: e2
12741	ir2: e3
12742---
12743name: nameref-2da
12744description:
12745	Testsuite for nameref (bound variables)
12746	Functions, argument given directly, after local
12747stdin:
12748	function foo {
12749		typeset bar=lokal baz=auch
12750		typeset -n v=bar
12751		echo entering
12752		echo !v: ${!v}
12753		echo !bar: ${!bar}
12754		echo !baz: ${!baz}
12755		echo bar: $bar
12756		echo v: $v
12757		v=123
12758		echo bar: $bar
12759		echo v: $v
12760		echo exiting
12761	}
12762	bar=global
12763	echo bar: $bar
12764	foo bar
12765	echo bar: $bar
12766expected-stdout:
12767	bar: global
12768	entering
12769	!v: bar
12770	!bar: bar
12771	!baz: baz
12772	bar: lokal
12773	v: lokal
12774	bar: 123
12775	v: 123
12776	exiting
12777	bar: global
12778---
12779name: nameref-3
12780description:
12781	Advanced testsuite for bound variables (ksh93 fails this)
12782stdin:
12783	typeset -n foo=bar[i]
12784	set -A bar -- b c a
12785	for i in 0 1 2 3; do
12786		print $i $foo .
12787	done
12788expected-stdout:
12789	0 b .
12790	1 c .
12791	2 a .
12792	3 .
12793---
12794name: nameref-4
12795description:
12796	Ensure we don't run in an infinite loop
12797time-limit: 3
12798stdin:
12799	baz() {
12800		typeset -n foo=fnord fnord=foo
12801		foo[0]=bar
12802	}
12803	set -A foo bad
12804	echo sind $foo .
12805	baz
12806	echo blah $foo .
12807expected-stdout:
12808	sind bad .
12809	blah bad .
12810expected-stderr-pattern:
12811	/fnord: expression recurses on parameter/
12812---
12813name: better-parens-1a
12814description:
12815	Check support for ((…)) and $((…)) vs (…) and $(…)
12816stdin:
12817	if ( (echo fubar)|tr u x); then
12818		echo ja
12819	else
12820		echo nein
12821	fi
12822expected-stdout:
12823	fxbar
12824	ja
12825---
12826name: better-parens-1b
12827description:
12828	Check support for ((…)) and $((…)) vs (…) and $(…)
12829stdin:
12830	echo $( (echo fubar)|tr u x) $?
12831expected-stdout:
12832	fxbar 0
12833---
12834name: better-parens-1c
12835description:
12836	Check support for ((…)) and $((…)) vs (…) and $(…)
12837stdin:
12838	x=$( (echo fubar)|tr u x); echo $x $?
12839expected-stdout:
12840	fxbar 0
12841---
12842name: better-parens-2a
12843description:
12844	Check support for ((…)) and $((…)) vs (…) and $(…)
12845stdin:
12846	if ((echo fubar)|tr u x); then
12847		echo ja
12848	else
12849		echo nein
12850	fi
12851expected-stdout:
12852	fxbar
12853	ja
12854---
12855name: better-parens-2b
12856description:
12857	Check support for ((…)) and $((…)) vs (…) and $(…)
12858stdin:
12859	echo $((echo fubar)|tr u x) $?
12860expected-stdout:
12861	fxbar 0
12862---
12863name: better-parens-2c
12864description:
12865	Check support for ((…)) and $((…)) vs (…) and $(…)
12866stdin:
12867	x=$((echo fubar)|tr u x); echo $x $?
12868expected-stdout:
12869	fxbar 0
12870---
12871name: better-parens-3a
12872description:
12873	Check support for ((…)) and $((…)) vs (…) and $(…)
12874stdin:
12875	if ( (echo fubar)|(tr u x)); then
12876		echo ja
12877	else
12878		echo nein
12879	fi
12880expected-stdout:
12881	fxbar
12882	ja
12883---
12884name: better-parens-3b
12885description:
12886	Check support for ((…)) and $((…)) vs (…) and $(…)
12887stdin:
12888	echo $( (echo fubar)|(tr u x)) $?
12889expected-stdout:
12890	fxbar 0
12891---
12892name: better-parens-3c
12893description:
12894	Check support for ((…)) and $((…)) vs (…) and $(…)
12895stdin:
12896	x=$( (echo fubar)|(tr u x)); echo $x $?
12897expected-stdout:
12898	fxbar 0
12899---
12900name: better-parens-4a
12901description:
12902	Check support for ((…)) and $((…)) vs (…) and $(…)
12903stdin:
12904	if ((echo fubar)|(tr u x)); then
12905		echo ja
12906	else
12907		echo nein
12908	fi
12909expected-stdout:
12910	fxbar
12911	ja
12912---
12913name: better-parens-4b
12914description:
12915	Check support for ((…)) and $((…)) vs (…) and $(…)
12916stdin:
12917	echo $((echo fubar)|(tr u x)) $?
12918expected-stdout:
12919	fxbar 0
12920---
12921name: better-parens-4c
12922description:
12923	Check support for ((…)) and $((…)) vs (…) and $(…)
12924stdin:
12925	x=$((echo fubar)|(tr u x)); echo $x $?
12926expected-stdout:
12927	fxbar 0
12928---
12929name: better-parens-5
12930description:
12931	Another corner case
12932stdin:
12933	( (echo 'fo	o$bar' "baz\$bla\"" m\$eh) | tr a A)
12934	((echo 'fo	o$bar' "baz\$bla\"" m\$eh) | tr a A)
12935expected-stdout:
12936	fo	o$bAr bAz$blA" m$eh
12937	fo	o$bAr bAz$blA" m$eh
12938---
12939name: echo-test-1
12940description:
12941	Test what the echo builtin does (mksh)
12942category: !shell:ebcdic-yes
12943stdin:
12944	echo -n 'foo\x40bar'
12945	echo -e '\tbaz'
12946expected-stdout:
12947	foo@bar	baz
12948---
12949name: echo-test-1-ebcdic
12950description:
12951	Test what the echo builtin does (mksh)
12952category: !shell:ebcdic-no
12953stdin:
12954	echo -n 'foo\x7Cbar'
12955	echo -e '\tbaz'
12956expected-stdout:
12957	foo@bar	baz
12958---
12959name: echo-test-2
12960description:
12961	Test what the echo builtin does (POSIX)
12962	Note: this follows Debian Policy 10.4 which mandates
12963	that -n shall be treated as an option, not XSI which
12964	mandates it shall be treated as string but escapes
12965	shall be expanded.
12966stdin:
12967	test -n "$POSH_VERSION" || set -o posix
12968	echo -n 'foo\x40bar'
12969	echo -e '\tbaz'
12970expected-stdout:
12971	foo\x40bar-e \tbaz
12972---
12973name: echo-test-3-mnbsd
12974description:
12975	Test what the echo builtin does, and test a compatibility flag.
12976category: mnbsdash
12977stdin:
12978	"$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12979	"$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12980	"$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12981expected-stdout:
12982	1=@foo.
12983	2=\x40foo-e \x2E
12984	3=\x40bar.
12985---
12986name: echo-test-3-normal
12987description:
12988	Test what the echo builtin does, and test a compatibility flag.
12989category: !mnbsdash,!shell:ebcdic-yes
12990stdin:
12991	"$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12992	"$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12993	"$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12994expected-stdout:
12995	1=@foo.
12996	2=\x40foo-e \x2E
12997	3=\x40foo-e \x2E
12998---
12999name: echo-test-3-ebcdic
13000description:
13001	Test what the echo builtin does, and test a compatibility flag.
13002category: !mnbsdash,!shell:ebcdic-no
13003stdin:
13004	"$__progname" -c 'echo -n 1=\\x7C$1; echo -e \\x4B' -- foo bar
13005	"$__progname" -o posix -c 'echo -n 2=\\x7C$1; echo -e \\x4B' -- foo bar
13006	"$__progname" -o sh -c 'echo -n 3=\\x7C$1; echo -e \\x4B' -- foo bar
13007expected-stdout:
13008	1=@foo.
13009	2=\x7Cfoo-e \x4B
13010	3=\x7Cfoo-e \x4B
13011---
13012name: utilities-getopts-1
13013description:
13014	getopts sets OPTIND correctly for unparsed option
13015stdin:
13016	set -- -a -a -x
13017	while getopts :a optc; do
13018	    echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
13019	done
13020	echo done
13021expected-stdout:
13022	OPTARG=, OPTIND=2, optc=a.
13023	OPTARG=, OPTIND=3, optc=a.
13024	OPTARG=x, OPTIND=4, optc=?.
13025	done
13026---
13027name: utilities-getopts-2
13028description:
13029	Check OPTARG
13030stdin:
13031	set -- -a Mary -x
13032	while getopts a: optc; do
13033	    echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
13034	done
13035	echo done
13036expected-stdout:
13037	OPTARG=Mary, OPTIND=3, optc=a.
13038	OPTARG=, OPTIND=4, optc=?.
13039	done
13040expected-stderr-pattern: /.*-x.*option/
13041---
13042name: utilities-getopts-3
13043description:
13044	Check unsetting OPTARG
13045stdin:
13046	set -- -x arg -y
13047	getopts x:y opt && echo "${OPTARG-unset}"
13048	getopts x:y opt && echo "${OPTARG-unset}"
13049expected-stdout:
13050	arg
13051	unset
13052---
13053name: wcswidth-1
13054description:
13055	Check the new wcswidth feature
13056stdin:
13057	s=何
13058	set +U
13059	print octets: ${#s} .
13060	print 8-bit width: ${%s} .
13061	set -U
13062	print characters: ${#s} .
13063	print columns: ${%s} .
13064	s=�
13065	set +U
13066	print octets: ${#s} .
13067	print 8-bit width: ${%s} .
13068	set -U
13069	print characters: ${#s} .
13070	print columns: ${%s} .
13071expected-stdout:
13072	octets: 3 .
13073	8-bit width: -1 .
13074	characters: 1 .
13075	columns: 2 .
13076	octets: 3 .
13077	8-bit width: 3 .
13078	characters: 1 .
13079	columns: 1 .
13080---
13081name: wcswidth-2
13082description:
13083	Check some corner cases
13084stdin:
13085	print % $% .
13086	set -U
13087	x='a	b'
13088	print c ${%x} .
13089	set +U
13090	x='a	b'
13091	print d ${%x} .
13092expected-stdout:
13093	% $% .
13094	c -1 .
13095	d -1 .
13096---
13097name: wcswidth-3
13098description:
13099	Check some corner cases
13100stdin:
13101	print ${%} .
13102expected-stderr-pattern:
13103	/bad substitution/
13104expected-exit: 1
13105---
13106name: wcswidth-4a
13107description:
13108	Check some corner cases
13109stdin:
13110	print ${%*} .
13111expected-stderr-pattern:
13112	/bad substitution/
13113expected-exit: 1
13114---
13115name: wcswidth-4b
13116description:
13117	Check some corner cases
13118stdin:
13119	print ${%@} .
13120expected-stderr-pattern:
13121	/bad substitution/
13122expected-exit: 1
13123---
13124name: wcswidth-4c
13125description:
13126	Check some corner cases
13127stdin:
13128	:
13129	print ${%?} .
13130expected-stdout:
13131	1 .
13132---
13133name: realpath-1
13134description:
13135	Check proper return values for realpath
13136category: os:mirbsd
13137stdin:
13138	wd=$(realpath .)
13139	mkdir dir
13140	:>file
13141	:>dir/file
13142	ln -s dir lndir
13143	ln -s file lnfile
13144	ln -s nix lnnix
13145	ln -s . lnself
13146	i=0
13147	chk() {
13148		typeset x y
13149		x=$(realpath "$wd/$1" 2>&1); y=$?
13150		print $((++i)) "?$1" =${x##*$wd/} !$y
13151	}
13152	chk dir
13153	chk dir/
13154	chk dir/file
13155	chk dir/nix
13156	chk file
13157	chk file/
13158	chk file/file
13159	chk file/nix
13160	chk nix
13161	chk nix/
13162	chk nix/file
13163	chk nix/nix
13164	chk lndir
13165	chk lndir/
13166	chk lndir/file
13167	chk lndir/nix
13168	chk lnfile
13169	chk lnfile/
13170	chk lnfile/file
13171	chk lnfile/nix
13172	chk lnnix
13173	chk lnnix/
13174	chk lnnix/file
13175	chk lnnix/nix
13176	chk lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself
13177	rm lnself
13178expected-stdout:
13179	1 ?dir =dir !0
13180	2 ?dir/ =dir !0
13181	3 ?dir/file =dir/file !0
13182	4 ?dir/nix =dir/nix !0
13183	5 ?file =file !0
13184	6 ?file/ =file/: Not a directory !20
13185	7 ?file/file =file/file: Not a directory !20
13186	8 ?file/nix =file/nix: Not a directory !20
13187	9 ?nix =nix !0
13188	10 ?nix/ =nix !0
13189	11 ?nix/file =nix/file: No such file or directory !2
13190	12 ?nix/nix =nix/nix: No such file or directory !2
13191	13 ?lndir =dir !0
13192	14 ?lndir/ =dir !0
13193	15 ?lndir/file =dir/file !0
13194	16 ?lndir/nix =dir/nix !0
13195	17 ?lnfile =file !0
13196	18 ?lnfile/ =lnfile/: Not a directory !20
13197	19 ?lnfile/file =lnfile/file: Not a directory !20
13198	20 ?lnfile/nix =lnfile/nix: Not a directory !20
13199	21 ?lnnix =nix !0
13200	22 ?lnnix/ =nix !0
13201	23 ?lnnix/file =lnnix/file: No such file or directory !2
13202	24 ?lnnix/nix =lnnix/nix: No such file or directory !2
13203	25 ?lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself =lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself: Too many levels of symbolic links !62
13204---
13205name: realpath-2
13206description:
13207	Ensure that exactly two leading slashes are not collapsed
13208	POSIX guarantees this exception, e.g. for UNC paths on Cygwin
13209category: os:mirbsd
13210stdin:
13211	ln -s /bin t1
13212	ln -s //bin t2
13213	ln -s ///bin t3
13214	realpath /bin
13215	realpath //bin
13216	realpath ///bin
13217	realpath /usr/bin
13218	realpath /usr//bin
13219	realpath /usr///bin
13220	realpath t1
13221	realpath t2
13222	realpath t3
13223	rm -f t1 t2 t3
13224	cd //usr/bin
13225	pwd
13226	cd ../lib
13227	pwd
13228	realpath //usr/include/../bin
13229expected-stdout:
13230	/bin
13231	//bin
13232	/bin
13233	/usr/bin
13234	/usr/bin
13235	/usr/bin
13236	/bin
13237	//bin
13238	/bin
13239	//usr/bin
13240	//usr/lib
13241	//usr/bin
13242---
13243name: crash-1
13244description:
13245	Crashed during March 2011, fixed on vernal equinōx ☺
13246category: os:mirbsd,os:openbsd
13247stdin:
13248	export MALLOC_OPTIONS=FGJPRSX
13249	"$__progname" -c 'x=$(tr z r <<<baz); echo $x'
13250expected-stdout:
13251	bar
13252---
13253name: debian-117-1
13254description:
13255	Check test - bug#465250
13256stdin:
13257	test \( ! -e \) ; echo $?
13258expected-stdout:
13259	1
13260---
13261name: debian-117-2
13262description:
13263	Check test - bug#465250
13264stdin:
13265	test \(  -e \) ; echo $?
13266expected-stdout:
13267	0
13268---
13269name: debian-117-3
13270description:
13271	Check test - bug#465250
13272stdin:
13273	test ! -e  ; echo $?
13274expected-stdout:
13275	1
13276---
13277name: debian-117-4
13278description:
13279	Check test - bug#465250
13280stdin:
13281	test  -e  ; echo $?
13282expected-stdout:
13283	0
13284---
13285name: case-zsh
13286description:
13287	Check that zsh case variants work
13288stdin:
13289	case 'b' in
13290	  a) echo a ;;
13291	  b) echo b ;;
13292	  c) echo c ;;
13293	  *) echo x ;;
13294	esac
13295	echo =
13296	case 'b' in
13297	  a) echo a ;&
13298	  b) echo b ;&
13299	  c) echo c ;&
13300	  *) echo x ;&
13301	esac
13302	echo =
13303	case 'b' in
13304	  a) echo a ;|
13305	  b) echo b ;|
13306	  c) echo c ;|
13307	  *) echo x ;|
13308	esac
13309expected-stdout:
13310	b
13311	=
13312	b
13313	c
13314	x
13315	=
13316	b
13317	x
13318---
13319name: case-braces
13320description:
13321	Check that case end tokens are not mixed up (Debian #220272)
13322stdin:
13323	i=0
13324	for value in 'x' '}' 'esac'; do
13325		print -n "$((++i))($value)bourne "
13326		case $value in
13327		}) echo brace ;;
13328		*) echo no ;;
13329		esac
13330		print -n "$((++i))($value)korn "
13331		case $value {
13332		esac) echo esac ;;
13333		*) echo no ;;
13334		}
13335	done
13336expected-stdout:
13337	1(x)bourne no
13338	2(x)korn no
13339	3(})bourne brace
13340	4(})korn no
13341	5(esac)bourne no
13342	6(esac)korn esac
13343---
13344name: command-shift
13345description:
13346	Check that 'command shift' works
13347stdin:
13348	function snc {
13349		echo "before	0='$0' 1='$1' 2='$2'"
13350		shift
13351		echo "after	0='$0' 1='$1' 2='$2'"
13352	}
13353	function swc {
13354		echo "before	0='$0' 1='$1' 2='$2'"
13355		command shift
13356		echo "after	0='$0' 1='$1' 2='$2'"
13357	}
13358	echo = without command
13359	snc 一 二
13360	echo = with command
13361	swc 一 二
13362	echo = done
13363expected-stdout:
13364	= without command
13365	before	0='snc' 1='一' 2='二'
13366	after	0='snc' 1='二' 2=''
13367	= with command
13368	before	0='swc' 1='一' 2='二'
13369	after	0='swc' 1='二' 2=''
13370	= done
13371---
13372name: command-pvV-posix-priorities
13373description:
13374	For POSIX compatibility, command -v should find aliases and reserved
13375	words, and command -p[vV] should find aliases, reserved words, and
13376	builtins over external commands.
13377stdin:
13378	PATH=/bin:/usr/bin
13379	alias foo="bar baz"
13380	bar() { :; }
13381	for word in 'if' 'foo' 'bar' 'set' 'true'; do
13382		command -v "$word"
13383		command -pv "$word"
13384		command -V "$word"
13385		command -pV "$word"
13386	done
13387expected-stdout:
13388	if
13389	if
13390	if is a reserved word
13391	if is a reserved word
13392	alias foo='bar baz'
13393	alias foo='bar baz'
13394	foo is an alias for 'bar baz'
13395	foo is an alias for 'bar baz'
13396	bar
13397	bar
13398	bar is a function
13399	bar is a function
13400	set
13401	set
13402	set is a special shell builtin
13403	set is a special shell builtin
13404	true
13405	true
13406	true is a shell builtin
13407	true is a shell builtin
13408---
13409name: whence-preserve-tradition
13410description:
13411	This regression test is to ensure that the POSIX compatibility
13412	changes for 'command' (see previous test) do not affect traditional
13413	'whence' behaviour.
13414category: os:mirbsd
13415stdin:
13416	PATH=/bin:/usr/bin
13417	alias foo="bar baz"
13418	bar() { :; }
13419	for word in 'if' 'foo' 'bar' 'set' 'true'; do
13420		whence "$word"
13421		whence -p "$word"
13422		whence -v "$word"
13423		whence -pv "$word"
13424	done
13425expected-stdout:
13426	if
13427	if is a reserved word
13428	if not found
13429	'bar baz'
13430	foo is an alias for 'bar baz'
13431	foo not found
13432	bar
13433	bar is a function
13434	bar not found
13435	set
13436	set is a special shell builtin
13437	set not found
13438	true
13439	/bin/true
13440	true is a shell builtin
13441	true is a tracked alias for /bin/true
13442---
13443name: duffs-device
13444description:
13445	Check that the compiler did not optimise-break them
13446	(lex.c has got a similar one in SHEREDELIM)
13447category: !shell:faux-ebcdic,!shell:ebcdic-yes
13448stdin:
13449	set +U
13450	s=
13451	typeset -i1 i=0
13452	while (( ++i < 256 )); do
13453		s+=${i#1#}
13454	done
13455	s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
13456	typeset -p s
13457expected-stdout:
13458	typeset s=$'\001\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\E\034\035\036\037 !"#$%&\047()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\u00A0\u20AC\uFFFD\357\277\276\357\277\277\360\220\200\200.'
13459---
13460name: duffs-device-ebcdic
13461description:
13462	Check that the compiler did not optimise-break them
13463category: !shell:ebcdic-no
13464stdin:
13465	set +U
13466	s=
13467	typeset -i1 i=0
13468	while (( ++i < 256 )); do
13469		s+=${i#1#}
13470	done
13471	#s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.' #XXX
13472	typeset -p s
13473expected-stdout:
13474	typeset s=$'\001\002\003\004\t\006\007\010\011\012\v\f\r\016\017\020\021\022\023\024\n\b\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\E\050\051\052\053\054\055\056\a\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077 ���������.<(+|&���������!$*);^-/�������Ѧ,%_>?���������`:#@\175="�abcdefghi�������jklmnopqr���Ƥ�~stuvwxyz���[ޮ����������ݨ�]��{ABCDEFGHI������}JKLMNOPQR������\\�STUVWXYZ������0123456789�����\377'
13475---
13476name: duffs-device-faux-EBCDIC
13477description:
13478	Check that the compiler did not optimise-break them
13479category: shell:faux-ebcdic
13480stdin:
13481	set +U
13482	s=
13483	typeset -i1 i=0
13484	while (( ++i < 256 )); do
13485		s+=${i#1#}
13486	done
13487	s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
13488	typeset -p s
13489expected-stdout:
13490	typeset s=$'\001\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\E\034\035\036\037 !"#$%&\047()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237������������������������������������������������������������������������������������������������\u00A0\u20AC\uFFFD￾￿�\220\200\200.'
13491---
13492name: stateptr-underflow
13493description:
13494	This check overflows an Xrestpos stored in a short in R40
13495category: fastbox
13496stdin:
13497	function Lb64decode {
13498		[[ -o utf8-mode ]]; local u=$?
13499		set +U
13500		local c s="$*" t=
13501		[[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
13502		local -i i=0 n=${#s} p=0 v x
13503		local -i16 o
13504
13505		while (( i < n )); do
13506			c=${s:(i++):1}
13507			case $c {
13508			(=)	break ;;
13509			([A-Z])	(( v = 1#$c - 65 )) ;;
13510			([a-z])	(( v = 1#$c - 71 )) ;;
13511			([0-9])	(( v = 1#$c + 4 )) ;;
13512			(+)	v=62 ;;
13513			(/)	v=63 ;;
13514			(*)	continue ;;
13515			}
13516			(( x = (x << 6) | v ))
13517			case $((p++)) {
13518			(0)	continue ;;
13519			(1)	(( o = (x >> 4) & 255 )) ;;
13520			(2)	(( o = (x >> 2) & 255 )) ;;
13521			(3)	(( o = x & 255 ))
13522				p=0
13523				;;
13524			}
13525			t=$t\\x${o#16#}
13526		done
13527		print -n $t
13528		(( u )) || set -U
13529	}
13530
13531	i=-1
13532	s=
13533	while (( ++i < 12120 )); do
13534		s+=a
13535	done
13536	Lb64decode $s >/dev/null
13537---
13538name: xtrace-1
13539description:
13540	Check that "set -x" doesn't redirect too quickly
13541stdin:
13542	print '#!'"$__progname" >bash
13543	cat >>bash <<'EOF'
13544	echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)
13545	Copyright (C) 2002 Free Software Foundation, Inc.'
13546	EOF
13547	chmod +x bash
13548	"$__progname" -xc 'foo=$(./bash --version 2>&1 | sed q); echo "=$foo="'
13549expected-stdout:
13550	=GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)=
13551expected-stderr-pattern:
13552	/.*/
13553---
13554name: xtrace-2
13555description:
13556	Check that "set -x" is off during PS4 expansion
13557stdin:
13558	f() {
13559		print -n "(f1:$-)"
13560		set -x
13561		print -n "(f2:$-)"
13562	}
13563	PS4='[(p:$-)$(f)] '
13564	print "(o0:$-)"
13565	set -x -o inherit-xtrace
13566	print "(o1:$-)"
13567	set +x
13568	print "(o2:$-)"
13569expected-stdout:
13570	(o0:sh)
13571	(o1:shx)
13572	(o2:sh)
13573expected-stderr:
13574	[(p:sh)(f1:sh)(f2:sh)] print '(o1:shx)'
13575	[(p:sh)(f1:sh)(f2:sh)] set +x
13576---
13577name: fksh-flags
13578description:
13579	Check that FKSH functions have their own shell flags
13580category: shell:legacy-no
13581stdin:
13582	[[ $KSH_VERSION = Version* ]] && set +B
13583	function foo {
13584		set +f
13585		set -e
13586		echo 2 "${-/s}" .
13587	}
13588	set -fh
13589	echo 1 "${-/s}" .
13590	foo
13591	echo 3 "${-/s}" .
13592expected-stdout:
13593	1 fh .
13594	2 eh .
13595	3 fh .
13596---
13597name: fksh-flags-legacy
13598description:
13599	Check that even FKSH functions share the shell flags
13600category: shell:legacy-yes
13601stdin:
13602	[[ $KSH_VERSION = Version* ]] && set +B
13603	foo() {
13604		set +f
13605		set -e
13606		echo 2 "${-/s}" .
13607	}
13608	set -fh
13609	echo 1 "${-/s}" .
13610	foo
13611	echo 3 "${-/s}" .
13612expected-stdout:
13613	1 fh .
13614	2 eh .
13615	3 eh .
13616---
13617name: fsh-flags
13618description:
13619	Check that !FKSH functions share the shell flags
13620stdin:
13621	[[ $KSH_VERSION = Version* ]] && set +B
13622	foo() {
13623		set +f
13624		set -e
13625		echo 2 "${-/s}" .
13626	}
13627	set -fh
13628	echo 1 "${-/s}" .
13629	foo
13630	echo 3 "${-/s}" .
13631expected-stdout:
13632	1 fh .
13633	2 eh .
13634	3 eh .
13635---
13636