NetBSD Problem Report #18852
Received: (qmail 23337 invoked by uid 605); 29 Oct 2002 13:20:12 -0000
Message-Id: <200210291321.g9TDLJh29585@snowdrop.l8s.co.uk>
Date: Tue, 29 Oct 2002 13:21:19 GMT
From: dsl@l8s.co.uk
Sender: gnats-bugs-owner@netbsd.org
Reply-To: dsl@l8s.co.uk
To: gnats-bugs@gnats.netbsd.org
Subject: /bin/sh doesn't expand "${a:-'x'}" correctly.
X-Send-Pr-Version: 3.95
>Number: 18852
>Category: bin
>Synopsis: /bin/sh doesn't expand "${a:-'x'}" correctly.
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Oct 29 13:21:00 +0000 2002
>Closed-Date: Tue Oct 29 15:29:58 +0000 2002
>Last-Modified: Tue Oct 29 15:30:01 +0000 2002
>Originator: David Laight
>Release: NetBSD 1.6I
>Organization:
none
>Environment:
System: NetBSD snowdrop 1.6I NetBSD 1.6I (GENERIC) #181: Thu Oct 24 14:06:02 BST 2002
dsl@snowdrop:/oldroot/usr/bsd-current/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
The shell incorrectly parses ${parameter:-word} when 'word'
contains quote characters and the entire construct is contained
within double quotes.
The construct "${x:-'$fred'}" might actually be useful...
(Spotted while looking for test cases for my fixed 'jobs'
code.))
>How-To-Repeat:
unset a;echo "${a:-'x'}"
should output the single character x, but it outputs the three
character sequence 'x'.
>Fix:
Unknown - the code for parsing quotes is already complicated,
someone who has some idea how it works might find it easier
to fix.
>Release-Note:
>Audit-Trail:
From: christos@zoulas.com (Christos Zoulas)
To: dsl@l8s.co.uk, gnats-bugs@gnats.netbsd.org
Cc:
Subject: Re: bin/18852: /bin/sh doesn't expand "${a:-'x'}" correctly.
Date: Tue, 29 Oct 2002 09:04:36 -0500
On Oct 29, 1:21pm, dsl@l8s.co.uk (dsl@l8s.co.uk) wrote:
-- Subject: bin/18852: /bin/sh doesn't expand "${a:-'x'}" correctly.
This is not necessarily correct. bash and zsh print 'x', ksh prints x.
We'll need to ask the gurus on that... I will do it.
christos
| >Description:
| The shell incorrectly parses ${parameter:-word} when 'word'
| contains quote characters and the entire construct is contained
| within double quotes.
| The construct "${x:-'$fred'}" might actually be useful...
| (Spotted while looking for test cases for my fixed 'jobs'
| code.))
| >How-To-Repeat:
| unset a;echo "${a:-'x'}"
| should output the single character x, but it outputs the three
| character sequence 'x'.
| >Fix:
| Unknown - the code for parsing quotes is already complicated,
| someone who has some idea how it works might find it easier
| to fix.
| >Release-Note:
| >Audit-Trail:
| >Unformatted:
-- End of excerpt from dsl@l8s.co.uk
State-Changed-From-To: open->closed
State-Changed-By: christos
State-Changed-When: Tue Oct 29 10:28:16 EST 2002
State-Changed-Why:
David Korn says:
| The correct answer is 'x'. What version of ksh is getting x?
| I just ran it with ksh93n and I get 'x' as expected.
| This behavior is for backward compatibility with the Bourne shell.
|
| In general, quoting outside of ${} and $() do not affect quoting
| inside. However, for backward compatibility, ksh treats
| the operators (+ - = ?) in ${} specially when quoted, so that
| "${x op string}"
| is treated as
| "${x op "string"}"
| for op = + - = and ?. In all other cases, the outer quotes
| do not affect the behavior of the inner quotes.
| Note that the standard does not specify the behavior in the case that
| outer quotes and inner quotes do not match, for example the behavior of
| "${x op "string}
| is not specified by the standard.
So, the bug is in pdksh that prints x instead of 'x'. All other shells
work properly. Please open a PR saying that ksh is broken :-)
From: David Laight <david@l8s.co.uk>
To: Christos Zoulas <christos@zoulas.com>
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: bin/18852: /bin/sh doesn't expand "${a:-'x'}" correctly.
Date: Tue, 29 Oct 2002 15:29:28 +0000
On Tue, Oct 29, 2002 at 09:04:36AM -0500, Christos Zoulas wrote:
> On Oct 29, 1:21pm, dsl@l8s.co.uk (dsl@l8s.co.uk) wrote:
> -- Subject: bin/18852: /bin/sh doesn't expand "${a:-'x'}" correctly.
>
> This is not necessarily correct. bash and zsh print 'x', ksh prints x.
> We'll need to ask the gurus on that... I will do it.
I'd only applied common sense, and looked what pdksh does.
$ b=z
$ echo ${x:-'$b'} "${x:-'$b'}" "${x:-\$b}" "${x:-"\$b"}" "${x:-"$b"}"
netbsd sh $b 'z' $b $b z
netbsd ksh $b $b $b $b z
solaris 8 sh $b 'z' $b $b z
solaris 8 ksh $b 'z' $b $b z
I wonder what the AT&T bourne sh does?
David
--
David Laight: david@l8s.co.uk
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.