Subject: RE: if construct doesn't work in makefile
From: "Bob Byrnes" <[email-masked]>
To: [email-masked]
Date: Thu, 11 Nov 2004 13:22:10 -0500

> >   if test [-dc:/tools]; then ...
> 
> ... in fact test seems to be happy with no spaces around the square
> brackets.  I think it may be only if you want to use the implicit form
> of test that the brackets need to be separated with spaces from the test
> inside them, so that bash spots them as a separate token.

No, you *always* need to separate "test" tokens with spaces.

The constructs ...

    test expr
and
    [ expr ]

... are equivalent.  Use either the "test" command or square brackets,
but not both.

If you do attempt to use square brackets in the expression, then they
have no special significance.

With a single argument, "test" just determines if the argument string
is non-null.  So the command ...

    test [-dc:/tools]

... always returns a true exit status, simply because the single argument
string "[-dc:/tools]" is not empty.

You can prove this by doing ...

    bash$ test [-d/does-not-exist] && echo yes
    yes

... or even ...

    bash$ test [1=2] && echo yes
    yes

--
Bob

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/