NetBSD Problem Report #3269

Received: (qmail-queue invoked from smtpd); 1 Mar 1997 09:57:58 -0000
Message-Id: <199703010953.UAA13444@zen.quick.com.au>
Date: Sat, 1 Mar 1997 20:53:18 +1100 (EST)
From: "Simon J. Gerraty" <sjg@quick.com.au>
Reply-To: sjg@quick.com.au
To: gnats-bugs@gnats.netbsd.org
Subject: /bin/sh: variable substitution broken
X-Send-Pr-Version: 3.95

>Number:         3269
>Category:       bin
>Synopsis:       /bin/sh: ${n:-word} variable substitution broken
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 01 02:05:02 +0000 1997
>Closed-Date:    Sat Mar 01 19:34:04 +0000 1997
>Last-Modified:  Sat Mar 01 19:34:23 +0000 1997
>Originator:     Simon J. Gerraty
>Release:        Feb22 tar_files + vm fixes
>Organization:
Zen Programming...
>Environment:

System: NetBSD zen.quick.com.au 1.2C NetBSD 1.2C (ZEN) #3: Fri Feb 28 12:18:37 EST 1997 root@zen.quick.com.au:/share/usr.src/sys/arch/i386/compile/ZEN i386


>Description:

Variable substitution of the form ${n:-word} in /bin/sh does not work
correctly, but ${n-word} is ok.

The script below should produce the output:

expect 1=one 2=two 3=three 4=d
1=one 2=two 3=three 4=d
1=one 2=two 3=three 4=d
expect 1=one 2=two 3=c 4=d
1=one 2=two 3=c 4=d
1=one 2=two 3=c 4=d
expect 1=one 2=b 3=c 4=d
1=one 2=b 3=c 4=d
1=one 2=b 3=c 4=d

but in fact produces:

expect 1=one 2=two 3=three 4=d
1=one 2=two 3=three 4=d
1=one 2=two 3=c 4=d
expect 1=one 2=two 3=c 4=d
1=one 2=two 3=c 4=d
1=one 2=b 3=c 4=d
expect 1=one 2=b 3=c 4=d
1=one 2=b 3=c 4=d
1=a 2=b 3=c 4=d

/bin/sh scripts are such a fundamental part of the system that this is
a rather serious problem.
>How-To-Repeat:

Run the following script:

:
set -- one two three
echo expect 1=$1 2=$2 3=$3 4=d
echo 1=${1-a} 2=${2-b} 3=${3-c} 4=${4-d}
echo 1=${1:-a} 2=${2:-b} 3=${3:-c} 4=${4:-d}

set -- one two 
echo expect 1=$1 2=$2 3=c 4=d
echo 1=${1-a} 2=${2-b} 3=${3-c} 4=${4-d}
echo 1=${1:-a} 2=${2:-b} 3=${3:-c} 4=${4:-d}

set -- one 
echo expect 1=$1 2=b 3=c 4=d
echo 1=${1-a} 2=${2-b} 3=${3-c} 4=${4-d}
echo 1=${1:-a} 2=${2:-b} 3=${3:-c} 4=${4:-d}

>Fix:

None, yet, sorry. 
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: christos 
State-Changed-When: Sat Mar 1 14:34:04 EST 1997 
State-Changed-Why:  
fixed 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(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.