Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Mar 1998 16:10:01 -0800 (PST)
From:      Martin Cracauer <cracauer@cons.org>
To:        freebsd-bugs
Subject:   Re: bin/6087: sh doesn't work properly on certain configuration scripts
Message-ID:  <199803220010.QAA26509@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/6087; it has been noted by GNATS.

From: Martin Cracauer <cracauer@cons.org>
To: giffunip@asme.org
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/6087: sh doesn't work properly on certain configuration scripts
Date: Sun, 22 Mar 1998 01:07:04 +0100

 In <199803211955.LAA15097@hub.freebsd.org>, giffunip@asme.org wrote: 
 > While using a configure script a problem with FreeBSD's sh was revealed.
 > The author of the script claims this is not a bash specific feature.
 > TBH Solaris doesn't have this bug either
 > >How-To-Repeat:
 > #!/usr/bin/sh
 > 
 > foobar=""
 > if test -n ""$foobar; then
 >          echo "Help, I am broken"
 > fi 
 
 Our /bin/sh expands ""$foobar to nothing, not to the empty string. I
 can't really judge over this, but it seems obvious that it should be
 the empty string and that we need to fix this.
 
 But there's another "interesting" detail in here: What does `test -n`
 return when no additional argument is passed? 
 
 FreeBSD's /bin/test (and bash2's) is supposed to support a call syntax 
 	test string
 without any option switch, which is supposed to return true if strings
 is not an empty string. That way, '-n' without an argument can be
 considered a non-empty string passed without option keys and true can
 be returned, which is what it does for now.
 
 ~(waldstrasse)44% bash -c 'test "" ; echo $?'
 1
 ~(waldstrasse)45% bash -c 'test "n" ; echo $?'
 0
 ~(waldstrasse)46% bash -c 'test "-n" ; echo $?'
 0
 ~(waldstrasse)47% bash -c 'test "-n" ""; echo $?'
 1
 ~(waldstrasse)48% bash -c 'test "-n" "n"; echo $?'
 0
 
 FreeBSD's /bin/test returns the same.
 
 Solaris' removed the non-switch syntax from from the manpage for
 /bin/test, while the actual program still supports it (Solaris
 2.5). If the string is what could be a switch, it is considered an
 error to be called with no additional argument. This is for the
 external program /bin/test, which is really an alias for /bin/ksh. You
 won't beleive how slow it is...
 
 ~(waldstrasse)32% /bin/test "" ; echo $?
 1
 ~(waldstrasse)33% /bin/test "n" ; echo $?
 0
 ~(waldstrasse)34% /bin/test "-n" ; echo $?
 /bin/test[8]: test: argument expected
 2
 ~(waldstrasse)35% /bin/test "-n" ""; echo $?
 1
 ~(waldstrasse)36% /bin/test "-n" "n"; echo $?
 0
 
 
 To make things worse, there is a bug in Solaris' /bin/sh built-in test:
 
 The intended behaviour seems to be exactly the same as for
 /bin/test. But it has a bug in that the whole script is terminated
 when `test -n` fails, see the third test, the echo command isn't
 executed. Someone obviously does an exit(1) here...
 
 ~(waldstrasse)22% /bin/sh -c 'test "" ; echo $?'
 1
 ~(waldstrasse)23% /bin/sh -c 'test "n" ; echo $?'
 0
 ~(waldstrasse)24% /bin/sh -c 'test "-n" ; echo $?'
 /bin/sh: test: argument expected
 ~(waldstrasse)25% /bin/sh -c 'test "-n" ""; echo $?'
 1
 ~(waldstrasse)26% /bin/sh -c 'test "-n" "n"; echo $?'
 0
 
 Could someone please look up the Posix standard for test(1)?
 
 I'm working on other syntax bugs of FreeBSD's /bin/sh and will add the
 expansion issue from above, but I can't promise anything soon. This is
 a very difficult area. For every sh bug in a given Unix clone you can
 bet that many places in the same OS depend on it.
 
 Martin
 -- 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer
 BSD User Group Hamburg, Germany     http://www.bsdhh.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199803220010.QAA26509>