zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Builtin test and parsing of conditionals
Date: Wed, 04 Sep 2013 10:39:40 -0700	[thread overview]
Message-ID: <130904103940.ZM28454@torch.brasslantern.com> (raw)
In-Reply-To: <20130904173159.19c55cd1@pwslap01u.europe.root.pri>

On Sep 4,  5:31pm, Peter Stephenson wrote:
} Subject: Re: Builtin test and parsing of conditionals
}
} On Wed, 04 Sep 2013 09:15:03 -0700
} Bart Schaefer <schaefer@brasslantern.com> wrote:
} > According to some discussion on the austin-group (POSIX) mailing list,
} > the following:
} > 
} > 	test ! -a !
} > 	test ! -o !
} > 	test ! = !
} > 
} > should all be parsed as comparing the string "!" to the string "!", but
} > zsh gets this right only in the last case.
} 
} I don't understand that.  -a means "and" and -o means "or", unless
} they're being interpreted as strings, but I don't see how that could be
} if ! is supposed to be interpreted as a string.

Sorry, perhaps I should have been clearer:  "! -a !" means to compare the
truth value "!" to the truth value of "!".  But "truth value" in "test"
is the same as "non-empty string" (true) and "empty string" (false) [not
0 or 1 as numeric values], so the -a operator is still comparing two
strings.

The point being that "!" should be parsed as a string, not as a negation
operator, in the three-argument case.

} So where does the
} implicit comparison come from?  If -a were taken as high precedence you
} might read it as
} 
} test -n ! -a n !
} test -n ! -a n !

Presuming you mean -a -n there, this is exactly how the austin-group
thread claims it should be interpreted, and is reportedly how ksh and
bash and GNU /usr/bin/test all interpret it.

} (Outside our control, but I imagine people aren't daft enough to rely on
} this sort of behaviour in new scripts...?)

I would hope so, but ...


  reply	other threads:[~2013-09-04 17:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-04 16:15 Bart Schaefer
2013-09-04 16:31 ` Peter Stephenson
2013-09-04 17:39   ` Bart Schaefer [this message]
2013-09-04 19:09     ` Peter Stephenson
2013-09-05 14:25       ` Bart Schaefer
2013-09-06 19:20         ` Peter Stephenson
2013-09-04 20:15     ` Chet Ramey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=130904103940.ZM28454@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).