From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28975 invoked by alias); 4 Sep 2013 16:15:12 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31693 Received: (qmail 16889 invoked from network); 4 Sep 2013 16:14:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <130904091503.ZM28369@torch.brasslantern.com> Date: Wed, 04 Sep 2013 09:15:03 -0700 X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Builtin test and parsing of conditionals MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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. This is especially annoying because test ! -f ! should be interpreted as the negation of the unary file-exists operator. This is probably complicated by the different meanings of -a and -o in [[ ... ]] as opposed to "test" because the same parser is used. Furthermore: test ! = -o a should be parsed as the negation of the comparison between the strings "=" and "a", implying that zsh also gets this wrong: test ! = = = which should return false (negation of (equal is the same string as equal)), rather than give a parse error as zsh does. (Zsh does get test = = = right.) Apparently the only way to do this correctly is to examine both argv[1] and the number of arguments, and skip to argv[2] for recursive descent parsing when argv[1] is "!" and there are four arguments. (As already mentioned in the zsh manual, what to do with more than four arguments in the absence of explicit parens is unclear [unspecified?].)