Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Jun 2000 13:42:59 -0700
From:      Andy Sparrow <andy@geek4food.org>
To:        freebsd-questions@freebsd.org
Subject:   Shell test(1) weirdness
Message-ID:  <20000613134259.A4793@BSDpc.geek4food.org>

next in thread | raw e-mail | index | archive | help

Hi,

I recently encountered a situation where the following snippet:

	#!/bin/sh

	GARBAGE=

	if [ -x $GARBAGE ]
	then
		echo "Yup, false positive"
	else
		echo "No, no such file"
	fi


Would print "Yup, false positive".

Of course, this is bad style, and one should quote variables in
shell tests if they might not be set (or even error out the script
if they're not set), which avoids the problem.

However, I didn't write this shell script, and I'm confused as to
why I don't get a "test: argument expected" error (and a FALSE
return status) like I do on other unices, given that this is
effectively executing:

	if /bin/test -x
	then
		# always true!?!
	else
		# what I'd expect
	fi

Without throwing an error, whereas the man page seems to indicate
that there's a required argument there...

Glancing at 'test.c' seems to indicate that it is prepared to print
out that error message, but it isn't being triggered by the above
case.

All the unary operators (b,c,d,f,g,x etc. etc.) seem to behave the
same way - it's the same on 2.x, 3.x and 4.x

Comments? Is this a known bug? Should I file a PR?


Cheers,

AS



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




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