From owner-freebsd-questions Tue Jun 13 13:43:13 2000 Delivered-To: freebsd-questions@freebsd.org Received: from BSDpc.geek4food.org (adsl-216-103-105-71.dsl.snfc21.pacbell.net [216.103.105.71]) by hub.freebsd.org (Postfix) with ESMTP id 637B937C0AF for ; Tue, 13 Jun 2000 13:43:03 -0700 (PDT) (envelope-from andy@geek4food.org) Received: by BSDpc.geek4food.org (Postfix, from userid 1000) id E0787745; Tue, 13 Jun 2000 13:42:59 -0700 (PDT) Date: Tue, 13 Jun 2000 13:42:59 -0700 From: Andy Sparrow To: freebsd-questions@freebsd.org Subject: Shell test(1) weirdness Message-ID: <20000613134259.A4793@BSDpc.geek4food.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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