bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ program


From: Bob Proulx
Subject: Re: [ program
Date: Mon, 2 Jan 2006 17:18:14 -0700
User-agent: Mutt/1.5.9i

Brian Beck wrote:
> After compiling the coreutils, I looked in the coreutils-5.93/src directory, 
> and noticed and executable named "[" doing an ls -l \[ gave me...
> 
> -rwxr-xr-x  1 bbeck bbeck 73120 2006-01-02 16:03 [

Yes.  That is normal and good.

> when I tried running the file it output...
> 
> ./[: missing `]'

Right.  It wants the trailing bracket so that it looks like this in an
if statement.

  if [ -f somefile ] ; then echo somefile exists ; fi

Except that '[' is a built-in with most shells today.  But for older
shells it was an external command.  POSIX requires it to exist to
support those older shells.  Also some commands allow you to exec
programs so there is still a possibility of the external test command
being run exlicitly.

  http://www.opengroup.org/onlinepubs/009695399/utilities/test.html

> on a whim I ran the program with "]" as an argument. It returned nothing.

Read the docs on how to use that command.

  0 arguments:
      Exit false (1).
  1 argument:
      Exit true (0) if $1 is not null; otherwise, exit false.

> I was wondering if that [ program is supposed to be there, or if
> it's a typo.  If I run info [ I get the info page for test, so I
> wasn't certain if they were related.

The test and [ commands are the same program these days.  In the old
days when test was external it was common to see this in scripts.

  if test -f somefile ; then echo somefile exists ; fi

These commands have been around for 30 years and it annoys people when
scripts stop working so the commands remain around to support them.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]