Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Date: Fri, 19 Aug 2005 15:45:57 -0400
From: Christopher Faylor <cgf-no-personal-reply-please@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: bash test -n && test -z return tru
Message-ID: <20050819194557.GA20394@trixie.casa.cgf.cx>
Reply-To: cygwin@cygwin.com
References: <081920051927.27330.430632BB00050BE200006AC222007507440A050E040D0C079D0A@comcast.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <081920051927.27330.430632BB00050BE200006AC222007507440A050E040D0C079D0A@comcast.net>
User-Agent: Mutt/1.5.8i

On Fri, Aug 19, 2005 at 07:27:55PM +0000, Eric Blake wrote:
>> On Fri, Aug 19, 2005 at 03:01:19PM -0400, Poor Yorick wrote:
>> >from reading the bash man pages, I would have thought the -n and -z were 
>> >mutually exclusive.  Therefore I don't understand this result:
>> >
>> >~>$ [ -n $(which nonexisingfilename 2>/dev/null) ] && [ -z $(which 
>> >nonexistingfilename 2&>/dev/null) ]  && echo hello
>> >hello
>> >~>$
>> >
>> >can anyone help explain this?
>> 
>> This defaults to
>> 
>>   [ -n ] && [ -z ] && echo hello
>> 
>> I would have expected a syntax error in that case.
>
>Nope.  POSIX requires that when there is one argument, it evaluates
>to true if it is not empty.

Thanks for the clarification.

>Neither -n nor -z is empty, so they are both true.  Remember, if there
>are no quotes around a word, it is subject to field splitting, such
>that an empty string disappears from the argument list altogether, and
>you are only giving one argument to [.

Er, yeah.  That's what I meant when I said:

"This defaults to:

  [ -n ] ..." ?

and then mentioned that the argument had to be quoted.

cgf

--
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/

