From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14075 invoked from network); 10 Jun 2021 00:15:43 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Jun 2021 00:15:43 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1623284143; b=IdXvB71Iagw22HoQbotdVnir/qcJwwSW/2cwZP29dqt0qBKFOeD4qEro6NUfudB/lCd1rck0v9 It6IUu9FDcpQtepvULDlqFu7pOvIwZqVI++asvzFDI9gdbPNhydimxVbCdPRTxSe3uiIkxDs95 Bzj7icnRURiAAWPrC51yqjAQfrvY3jR+PY4+cLYJhgUwsoZB5aTtpXVl4seQaejh5yeCZ2XDEv qXrvb7jmgugKPijiKiuwEFHRH32pM2pQ5QDkw0IRKrKG1d/eV11IZhp4RzGuohtiVjw2FHZ6lh FfL3f3aE8vvm/arJJbPEkXzDfDy4a62vzKV1GD1NEFT2Rg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f171.google.com) smtp.remote-ip=209.85.167.171; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1623284143; bh=xn0cW7C4NWGcAVwCwxe8HdkWi4vPKpjBRZmPw66mVQY=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=sc1Hg8PZBFm8GMTxLT2UxxYzAyst2MUKnKusiWOxhD5OnTaP5N0SBSAJxRq4qeltHViFKEsPTF JqnSY/SFHp0mN/pN0JHXGjplwhUyS76c7C6khd6kfPHKBePYZ7oX3W2FUEyp3il4qNy2dHisIt ggAjWnFYnxrpc0rEpgCjXPD25nTy6BezTntz/NqXTEWgX3J76Slcp9PK7e+3xnxnWO7ECqTvwh mHF4a3mwYuOk4OJSkzysBfGj5BwBtMAbeoRZzUVN22Jgbk7GK1Z6Sz6+4UGu6aabR7nRBzCa0k vOKolRtRzUkJhJjHFIXEsiwPfZY3SBCLjF67y1myCSCDHQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=PcQrQ+R1EB9aElsZc6ltq7dVdFGVEgq2kcPmRCv6lLg=; b=qxF6TxyWwMj9Lw27HD+cRkQT1R jtrX/gkSOYy8gQMEkpjhL9/6dZWcYpEXFbi5vNTfCH6mMYn12ybcgKobpPGrpv0EW6oPcOAnjmF15 PwltLtsRSrdOpANReTwjHCn6pMRmpejMCAluqftz8k+Fp9mWFaAGhB9dWall8s878W37mH+lYpUOB /LU4JiGhavtwnTszatZ8RuMEkpGU0pMK0VEm9VOd+COMgj/yt0c2PSrY/B7q4W7Lt1bLFAUEC8zVU wqUeAAWhMgUmGb5kbEIdpcocd0isM2Ie8JPKIptaV1sAomPHHBZ50y0nuwi2HOcRlqKIbxIm7emHq EfdZ8jHQ==; Received: from authenticated user by zero.zsh.org with local id 1lr8MI-000Prl-Kg; Thu, 10 Jun 2021 00:15:42 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f171.google.com) smtp.remote-ip=209.85.167.171; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-oi1-f171.google.com ([209.85.167.171]:40525) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lr8Lj-000PY8-FV; Thu, 10 Jun 2021 00:15:08 +0000 Received: by mail-oi1-f171.google.com with SMTP id r17so156262oic.7 for ; Wed, 09 Jun 2021 17:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=PcQrQ+R1EB9aElsZc6ltq7dVdFGVEgq2kcPmRCv6lLg=; b=nMZabtGPyzgLAZqoCIo6D52hLSe0CNlzPaqxYSzDSY++xMvN7gjLPdj6KDwnB6sb7x ZP6FP7XXgPEbk2aIT8yDUN86m2a1ez+AQs4z/xqfm/9n5LMmV45nZcAv8rYmgYLQqCxk wYv9fGsBU2Ur54PB3cBArXIignHNx12v+R+yfecl5smbgs3lFt/qCJy0+SaqJqxtp70R QjbkemN4iO5/UHX16aVbMbBRsoCqUrDxqdHQai6vTABZwywCAQL0w/jmC4+Q60myvzk0 wsrCvWJNBXhfqQm6iBD8SRoFRnH9A7QzFq9vqlfisxvrDDHF/YhXKi1Cm07z6Jf6JAoR fo9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=PcQrQ+R1EB9aElsZc6ltq7dVdFGVEgq2kcPmRCv6lLg=; b=diAHFw71O0G5D2QCTaX6MYSdnSUbJRUHNS0TKmULeixG4ESbAkJLYd3anZ5hhCycN/ 2Y0UssiqbiTEFVSDUix5MePDc7KfgVZtxeYnspZTmLM1GYR551HvqqPECRagPhe4W686 ZacIVB87lvAjCkPNZhC/OF54IIrLIdrf3s2WDMJEGiuwkvVxbv+b++gaM2+U8T356e0i hCHJvpGdROpg6VL/u1/Od0J12CsjSQYsK5nh5XIVWPwtNY8EIsyRXnw4vlQz6IP7NHqx u11rpfr3Jy57rX/Ak6CHRZ8HSy5F/YJ6uKhqQVCVVG3ADVcrQRfFlV7kKfNdYIjilEmB 6ilw== X-Gm-Message-State: AOAM530QB3OhvnUjjv6jw5vV5b+jBs2c4n4ovEvY4GOxs7ZGUoNLo6N9 GgVIFp2Xgu+//CH8gdAMjiwamCkNyLxiqNJEE21dM50RlzU= X-Google-Smtp-Source: ABdhPJzI+Y94yDtYGJGvNqtyG2B8A6v8q1b3SqI5yI0SnEpZ4+Xotqt72D7C2JbqfxbzVU6gNfKI/UmY/QkkEkFeGow= X-Received: by 2002:aca:5cc2:: with SMTP id q185mr8360426oib.173.1623284106174; Wed, 09 Jun 2021 17:15:06 -0700 (PDT) MIME-Version: 1.0 References: <1629605749.599911.1622710481163@mail2.virginmedia.com> <20210603131347.i7bv7ao7j3hk3a2e@chazelas.org> <20210604080200.pnlzjexcuu3oyjcy@chazelas.org> <20210604202116.gnxqqegfnmki2i57@chazelas.org> <20210605170531.af3rj3iurjvvcmdw@chazelas.org> In-Reply-To: <20210605170531.af3rj3iurjvvcmdw@chazelas.org> From: Bart Schaefer Date: Wed, 9 Jun 2021 17:14:55 -0700 Message-ID: Subject: Square brackets in command position To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 49048 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 Sat, Jun 5, 2021 at 10:05 AM Stephane Chazelas wrote: > > 2021-06-04 17:20:29 -0700, Bart Schaefer: > [...] > > > array[1 + 1]=4 > > > > > > That is pretty annoying. > > > > That's just shell whitespace rules, though. > > Note that all other shells that support a[1]=value (ksh, pdksh, > bash) do it. Chip will probably correct me, but from some experiments with bash it appears that (with the exception of '[' all alone, to invoke "test") an (unquoted) '[' in a word in command position always begins an expression that must be bounded by a closing (unquoted) ']' (even if that means continuing to the PS2 prompt). Thus for example $ a[ 1 + 1 ]b globs to a file named "a b" in the current directory and does a path search to run that as a command. Note that $ [a ]b globs to "ab" or " b" (leading space there if that's hard to see), it's not what's to the left of '[' that triggers this. Thus it's not just assignments that have command-position magic, character classes can have embedded (unquoted) spaces there as well. This breaks if you are looking for a file named e.g. "a+=" because ']=' turns the whole thing into an array element assignment. > There is variation in behaviour between shells if the first word > starts with name[ and either a matching ] or matching ] followed > by = is not found, and how that matching is done or what kind of > quoting are supported inside the [...]. That doesn't give us any good ideas on where to start. Of course zsh's parsing hash keys using the same quoting rules as arithmetic was a quick way to slurp hash[string] through the existing array[math] parser at the time, and in retrospect probably should have been given its own rules. > In zsh, that would be even less problematic as (at least when > not in sh emulation), zsh complains about unmatched [s or ]s As mentioned before, that's the BAD_PATTERN setopt, which can be turned off independent of emulation, so it might be a stretch to say we wouldn't be breaking anything.