Subject: bin/15579: /bin/sh parsing of complex ${variable:-word} sbstitutions
To: None <gnats-bugs@gnats.netbsd.org>
From: Alan Barrett <apb@cequrux.com>
List: netbsd-bugs
Date: 02/11/2002 19:52:08
>Number:         15579
>Category:       bin
>Synopsis:       /bin/sh parsing of complex ${variable:-word} sbstitutions
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 11 09:56:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Alan Barrett
>Release:        NetBSD 1.5ZA
>Organization:
Not much
>Environment:
System: NetBSD 1.5ZA 
Architecture: i386
Machine: i386
>Description:
NetBSD's /bin/sh gets confused by complex ${var:-word} substitutions
in which the word includes quotation marks and curly brackets.

In a construct like

	foo=${foo:-"'{}'"}

the variable foo should be left unchanged is it was already set and
non-null, and should be set to "'{}'" if it was unset (or set but null).

NetBSD's /bin/sh incorrectly appends "'}" to the variable if it was
already set and non-null, and incorrectly sets the variable to "'{'}" is
it was unset.

>How-To-Repeat:

$ unset foo ; expected="'{}'"
$ foo=${foo:-"'{}'"}
$ echo "foo is :$foo: should be :$expected:"
foo is :'{'}: should be :'{}':

$ foo=xxx ; expected="$foo"
$ foo=${foo:-"'{}'"}
$ echo "foo is :$foo: should be :$expected:"
foo is :xxx'}: should be :xxx:

>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: