[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] if and [ ] equivalence
From: |
Eric Blake |
Subject: |
Re: [Help-bash] if and [ ] equivalence |
Date: |
Mon, 12 Mar 2012 11:54:59 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1 |
On 03/12/2012 11:45 AM, Ken Irving wrote:
> On Mon, Mar 12, 2012 at 12:22:36AM -0400, DJ Mills wrote:
>> ... '[' is just a command, like any other. Same with '&&'
>
> Most commands ('&&' included) don't require terminating constructs
> further along the command line, so '[' seems unusual to me.
>
> I suppose the standalone command /usr/bin/[ may check for ] as its
> last argument, but otherwise the shell probably parses the whole [
> ... ] construct.
>
> I prefer using 'test' over '[' in scripts, but is the latter more
> efficient?
Per POSIX, 'test' and '[' are synonyms, except that '[' requires a
terminating ']'. Use of 'test' is preferred by some programmers
(especially in autoconf, where [] can be confused with autoconf's choice
of m4 quoting mechanism); use of '[' is preferred by others (since even
with the mandatory space before the ']', 'test a' is longer than '[ a ]').
--
Eric Blake address@hidden +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature