From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 2A69A2234C for ; Wed, 3 Apr 2024 15:59:44 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1712152784; b=WGQLMalMBRrC6KQrO2TwyoPQDnf3vvsSSDMJjSxCL5mcWEKtiKMO5FcoTGImmpuzBD4+R6eN9u C6Ckjs3TWC5EWPvhJ5nVxb6SGDXQzBkMfN9QW6sSIcsc9qviBaTxtLu5tUeUxxskWC4Afmi2sN wGis0Cc0FKhYZLFU5H66R4VgxZs/woLq8J9z+TApj4DCZuvfwkkplkq8RircS631DSS2gHM/7d Sbni1PiUsz/lkE9Z728tSxJ0q2GFtpfXKmhsfYuqpgCsHl+ZI6SRGqpW8ryX5RS5MlDOPLeQMB 7EmfiCxQP4u+5E5ZjPj/ROIc/PEt5jMfbmYsfsjVuUW4Og==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (joooj.vinc17.net) smtp.remote-ip=155.133.131.76; dmarc=none header.from=vinc17.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1712152784; bh=Dw8olRxaSflnOOCwu2s2u5dc7VdVc9jv/NWBGmGgSQo=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:To:From:Date:DKIM-Signature; b=WKwoO8L3l9+G6aYL+heNrbw6FNjJ8ONolOtMxijIxrnUZ+kG1x4Y04DTFBVLgaR/Hg9xGxymmP AJ1KO9ySxY29ys5w/Ls1s8p9wmmq37PVdfIGk6DMJXlTkAkMfUJVHTRpI+TDKsP5R9Pu3lEVW8 GriDKmvYn9PxBXoqhSVrUG655JfckhaneImCwFjE2VcwK4BQBj6V9TbLcjSVYoJc6FyFgOgAC+ JSVQX/ncBbg2nTaeOafONmGiS67A+SgtaVeLVgCNuNVGhwcRwl6CWyaQD7ysUwfZLx23lhqOyX RUNpqaMX30eYzaZzTFH3AacQZs81RjH+RfKqc6GR2LeRqQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=GagRTR1aFfMZFyQFDeauRnDhCmO8mW8DJkSJUi+hocc=; b=XuP/DUcwsVbTwLM4P0TvDhi8XI 1UHYD3u6k6uZuG0/qRQXXGXwXbvX5e4b1Xtdd8Uc6Cy1RBm1qKCnLhXszJq+4Cz/q147u+FvOMtfJ D3p+VGbTkR7bNveh8xfvUKAQHVpgMpOxFdY+gOnfc4JN8ngmmKoxqXLyR5epu6UTEdDbr5tWR8oym KEYDBuSrf4W/4hQcDQFv4MF/ZWGtLMROYJLK780cwiR14evC2l9W2CX3e454zexpqijgNoJg581Df 6CreqbvP6HMp2V0hr/bDC1kg/MNFUY60EJ8CSzcUMai+vzMGBpUW46sxpgZZFHqj5oVtiN/mQVFIf paVyOBFg==; Received: by zero.zsh.org with local id 1rs19U-000DGO-2v; Wed, 03 Apr 2024 13:59:44 +0000 Authentication-Results: zsh.org; iprev=pass (joooj.vinc17.net) smtp.remote-ip=155.133.131.76; dmarc=none header.from=vinc17.net; arc=none Received: from joooj.vinc17.net ([155.133.131.76]:44856) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rs197-000Cwc-C2; Wed, 03 Apr 2024 13:59:26 +0000 Received: from smtp-qaa.vinc17.net (135.197.67.86.rev.sfr.net [86.67.197.135]) by joooj.vinc17.net (Postfix) with ESMTPSA id ACFA43D3; Wed, 3 Apr 2024 15:59:20 +0200 (CEST) Received: by qaa.vinc17.org (Postfix, from userid 1000) id 6C0A9CA00B3; Wed, 03 Apr 2024 15:59:20 +0200 (CEST) Date: Wed, 3 Apr 2024 15:59:20 +0200 From: Vincent Lefevre To: zsh-workers@zsh.org Subject: Re: behavior of test true -a \( ! -a \) Message-ID: <20240403135920.GA112457@qaa.vinc17.org> Mail-Followup-To: zsh-workers@zsh.org References: <20240321100710.GA164665@qaa.vinc17.org> <1443395979.5911218.1711016896863@mail.virginmedia.com> <20240321110444.GC164665@qaa.vinc17.org> <1507569659.5899391.1711020579178@mail.virginmedia.com> <1255066524.6153675.1711384714319@mail.virginmedia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.2.12+69 (354c5b11) vl-149028 (2023-12-10) X-Seq: 52871 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On 2024-03-25 10:36:13 -0700, Bart Schaefer wrote: > So in other words you're intentionally breaking this: > > % test \( ! -a \) \) > test: too many arguments I suppose that with zsh 5.9, zsh sees that -a is a binary primary (so, no contradictions with POSIX[*] since for the decision of the matching parenthesis, at least 5 arguments need to be considered, and this is where the results are unspecified). [*] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html > In the name of "fixing" this: > > % test \) -a \( ! -a \) > > If we're arguing here based on spec, POSIX says the below should > return 1 because $2 is a "binary primary" which takes precedence over > parens, but it's broken with or without this patch: > > % test \( -a \( > test: parse error > > To be fair, /bin/test on MacOS and /usr/bin/test on Ubuntu both choke > (or not) in exactly those same cases. In Debian: With dash 0.5.12-6: $ test \( -a \( ; echo $? sh: 1: test: closing paren expected 2 With ksh93u+m 1.0.8-1: $ test \( -a \( ; echo $? ksh93: test: argument expected 2 With mksh 59c-35: $ test \( -a \( ; echo $? 0 With bash 5.2.21-2: vinc17@qaa:~$ test \( -a \( ; echo $? 0 With coreutils 9.4-3.1: $ /usr/bin/test \( -a \( ; echo $? /usr/bin/test: ‘-a’: unary operator expected 2 Note that POSIX says that the results are unspecified if $1 is '(' and $3 is ')', but here both $1 and $3 are '('. So the rule is: If $2 is a binary primary, perform the binary test of $1 and $3. so that 0 is expected (only mksh and bash are correct). IMHO, once you have reached a subsequence with at most 4 arguments (like here), you should apply the POSIX rules. Doing otherwise is surprising. Said otherwise, I suppose that the following should work: * If there are at most 4 arguments, apply the POSIX rules. * If the first argument is an opening parenthesis, choose a rule to determine the matching closing parenthesis (say, arg n), or possibly regard this first argument as a string. * In the case of a real opening parenthesis, arg n needs to be the last argument or be followed by -a or -o. Apply the test algorithm on arg 2 to n-1, and in case of -a or -o, also on arg n+2 to the last arg (possibly with early termination in the parsing). * Otherwise: Choose a rule to determine the operator. Note that the obtained expression associated with this operator is necessarily followed by a -a or -o binary primary (say, arg n). Evaluate the expression and apply the test algorithm on arg n+1 to the last arg (possibly with early termination in the parsing). -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)