xref: /freebsd/bin/sh/tests/expansion/plus-minus3.0 (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1
2e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
3h='##'
4failures=''
5ok=''
6
7testcase() {
8	code="$1"
9	expected="$2"
10	oIFS="$IFS"
11	eval "$code"
12	IFS='|'
13	result="$#|$*"
14	IFS="$oIFS"
15	if [ "x$result" = "x$expected" ]; then
16		ok=x$ok
17	else
18		failures=x$failures
19		echo "For $code, expected $expected actual $result"
20	fi
21}
22
23# We follow original ash behaviour for quoted ${var+-=?} expansions:
24# a double-quote in one switches back to unquoted state.
25# This allows expanding a variable as a single word if it is set
26# and substituting multiple words otherwise.
27# It is also close to the Bourne and Korn shells.
28# POSIX leaves this undefined, and various other shells treat
29# such double-quotes as introducing a second level of quoting
30# which does not do much except quoting close braces.
31
32testcase 'set -- "${p+"/et[c]/"}"'		'1|/etc/'
33testcase 'set -- "${p-"/et[c]/"}"'		'1|/et[c]/'
34testcase 'set -- "${p+"$p"}"'			'1|/etc/'
35testcase 'set -- "${p-"$p"}"'			'1|/et[c]/'
36testcase 'set -- "${p+"""/et[c]/"}"'		'1|/etc/'
37testcase 'set -- "${p-"""/et[c]/"}"'		'1|/et[c]/'
38testcase 'set -- "${p+"""$p"}"'			'1|/etc/'
39testcase 'set -- "${p-"""$p"}"'			'1|/et[c]/'
40testcase 'set -- "${p+"\@"}"'			'1|@'
41testcase 'set -- "${p+"'\''/et[c]/'\''"}"'	'1|/et[c]/'
42
43test "x$failures" = x
44