Subject: bin/3269: /bin/sh: variable substitution broken
To: None <gnats-bugs@gnats.netbsd.org>
From: Simon J. Gerraty <sjg@quick.com.au>
List: netbsd-bugs
Date: 03/01/1997 20:53:18
>Number:         3269
>Category:       bin
>Synopsis:       /bin/sh: ${n:-word} variable substitution broken
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar  1 02:05:02 1997
>Last-Modified:
>Originator:     Simon J. Gerraty
>Organization:
Zen Programming...
>Release:        Feb22 tar_files + vm fixes
>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. 
>Audit-Trail:
>Unformatted: