NetBSD Problem Report #221
From gnats Sat Apr 9 17:17:29 1994
Received: from darling.idt.unit.no (darling.idt.unit.no [129.241.111.171]) by sun-lamp.cs.berkeley.edu (8.6.8/8.6.6) with ESMTP id RAA04935 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Sat, 9 Apr 1994 17:17:28 -0700
Message-Id: <199404100017.CAA01703@darling.idt.unit.no>
Date: Sun, 10 Apr 1994 02:17:19 +0200
From: jarle@idt.unit.no
Reply-To: jarle@idt.unit.no
To: gnats-bugs@sun-lamp.cs.berkeley.edu
Subject: test unary operators with no argument always return true
X-Send-Pr-Version: 3.2
>Number: 221
>Category: bin
>Synopsis: /bin/test unary operators without argument always return true
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: gnats-admin
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Apr 09 17:20:02 +0000 1994
>Closed-Date: Sun Apr 10 05:37:12 +0000 1994
>Last-Modified: Fri Nov 23 13:22:35 +0000 2012
>Originator: Jarle Greipsland
>Release: current
>Organization:
"Redundancy department of Redundancy"
>Environment:
Intel 486DX2-66, NetBSD-current, do., misc.
System: NetBSD darling.idt.unit.no 0.9a DARLING#16 i386
>Description:
One or more of /bin/test (/bin/[) unary operators return a true value if their
arguments are missing. I find this behaviour somewhat counter-intuitive.
For all I know this may be the expected behaviour according to some standard,
but I'm not well enough versed in those to say. (Heck, I don't know who would
be the most scared if we met in a dark alley, me or the POSIX.....)
>How-To-Repeat:
Running /bin/sh
$ if [ -r ]; then
> echo I can read the file
> fi
I can read the file
$
On a SunOS box this gives:
$ if [ -r ]; then
> echo I can read the file
> fi
test: argument expected
$
as I would expect.
>Fix:
Note: As I know diddly'squat about POSIX this may not be correct, but
still, I think it's better :-)
*** test.c.orig Sun Apr 10 02:07:35 1994
--- test.c Sun Apr 10 02:02:34 1994
***************
*** 138,141 ****
--- 138,146 ----
case 1: /* % test arg */
/* MIPS machine returns NULL of '[ ]' is called. */
+ if ( argv[1] != 0 &&
+ (lookup_op(argv[1], unary_op) != -1 ||
+ lookup_op(argv[1], binary_op) != -1 ||
+ lookup_op(argv[1], andor_op) != -1))
+ syntax();
return (argv[1] == 0 || *argv[1] == '\0') ? 1 : 0;
break;
The resulting output from running "/bin/test -r" will now be
"test: syntax error" (which is a bit more helpful the day one of your
shell variables suddenly expands to nothing).
-jarle
----
"The solution implemented here works amazingly well in most
circumstances, and, being essentially half-assed, is more in keeping
with the spirit of Unix. Blech."
-- cmushell.el comment
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: cgd
State-Changed-When: Sat Apr 9 22:37:12 PDT 1994
State-Changed-Why:
fixed
(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.