delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/08/20/04:34:13

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Subject: Re: bash test -n && test -z return tru
From: Hannu E K Nevalainen <_garbage_collector_ AT telia DOT com>
To: cygwin AT cygwin DOT com
In-Reply-To: <20050819194557.GA20394@trixie.casa.cgf.cx>
References: <081920051927 DOT 27330 DOT 430632BB00050BE200006AC222007507440A050E040D0C079D0A AT comcast DOT net> <20050819194557 DOT GA20394 AT trixie DOT casa DOT cgf DOT cx>
Date: Sat, 20 Aug 2005 10:36:05 +0200
Message-Id: <1124526965.7467.37.camel@p450>
Mime-Version: 1.0
X-IsSubscribed: yes

On Fri, 2005-08-19 at 15:45 -0400, Christopher Faylor wrote:
> 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

NOTE: I have serious intent with this inlay, please put away your
personal feelings. Here we go...

Saying "defaults to" something; to me this means that (without specified
arguments) you get a certain behaviour.

People who aren't initiate on the subject (or fluent in English!) tend
to stumble on wording, so this time the words "defaults to" didn't
clarify what actually happens.

An attempt to specify arguments was present - leading to confusion.
Why:  $(which nonexisingfilename 2>/dev/null)  "expands" to a null
string - and thus a fallback to the special default case.

I think a simple substitution of 
	"This defaults to:"
with 
	"After command substitution of 'which' you end up with:"
would have said more.

An example of how easy it is to confuse ppl though not really intending
to do so?
<Fill in: researh project about how to write good documents>


WRT confusion:

-- Redhat Fedora 3 --
$ man bash
/command substitution

Here the description of the two forms of command substitution has a
NONWORKING form of quotes around the second form example.
 -> TOTAL confusion for an non-initiate.

[henk AT p450 ~]$ echo ‘echo Boo‘
‘echo Boo‘

Correct output, with the right quotes is just "Boo".
  -> ` <- the right one, does this quote end up correctly here? 

[henk AT p450 ~]$ echo `echo Boo`
Boo

I wouldn't be surprised if this is the case for "man bash" in cygwin
too.

-- 
/Hannu E K Nevalainen


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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019