From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id b01e54e6 for ; Thu, 8 Aug 2019 21:49:02 +0000 (UTC) Received: (qmail 10817 invoked by alias); 8 Aug 2019 21:48:57 -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: List-Unsubscribe: X-Seq: 44645 Received: (qmail 18502 invoked by uid 1010); 8 Aug 2019 21:48:57 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm1-f46.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25531. spamassassin: 3.4.2. Clear:RC:0(209.85.128.46):SA:0(-2.0/5.0):. Processed in 1.811936 secs); 08 Aug 2019 21:48:57 -0000 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.128.46 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=/wyxWgQ6emHwyBsW+bPDbTe7R+8SqOeErDawFHXqZ4Y=; b=uJNVgQO8tXW268dpsmMZ2J6KkCJ8/cs6lkQl87H5uFev20xh/re1QYBODNJ+bjfi+W Nwa51PISDzCgL9FPjmrIELGoMhn1aJgqgZw8zhNX1ghhlAi0ryxwlozK0oPmXMYNuoqv PxY87vR9Nuih4foh23QnhF3PGpv2aozvvZgeKxhsG4djf4B9FG93UMy8UtWuJv+AGX7O J55hkadj0CNHYrtjcxF4kX46+B7BjdlD7g6EfOg1YbnI/3LYgOKwqSb8sOlkomy/WUJ0 G62yq9icWUiqFbs8zX8KG9BFDgNdwt+9X7tGwD0zjJaUHi5GCTSq8mgqaBu9Gm9YIi2U ZJyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=/wyxWgQ6emHwyBsW+bPDbTe7R+8SqOeErDawFHXqZ4Y=; b=aWrBy8hLHmE6KeHUlhe+ZHV+J26n8hWhYMnX7CHYlbQA0vbz8ekBfIijSCGsNEIao/ 5mX7scGd6j4dfyUS47Bd1MK33t/pvgEKV9uPW5qrb4tBZrLBYKLqS6MdMO34E6ZIiztS JWhj+sSfh9QYfZqHGAaFCJiX1dk2hwzenUL00nwsC/Di7C4WAt+C3EyboKbpXCIvFmYt G8dC12fu7ZCuj7dal7xmq+jNNWKC6ue4tKbGkf3qoCh75nLxJZk6A2uf1g1m6AumdYu1 vn6MVO6zCxjJJpOuYRssw6d+WyG5zHpPubnq/G++BqsskdWMvbswBGMeFz0KW1SMT+Lt S/QA== X-Gm-Message-State: APjAAAWX0i7/lFGto8YVw/VjwUUBj35KPvR9ubsZKBnOVjiuyQwPUHIr TX00wxFI1xIMC4bf22AQ7bk= X-Google-Smtp-Source: APXvYqxq2iIPUnZIMiEvJfOuWkHbTZQfkIBPPhCEr0+5hOafUay9gSFleCzulKErDf9G6QmDssJWWQ== X-Received: by 2002:a1c:107:: with SMTP id 7mr6783391wmb.84.1565300901505; Thu, 08 Aug 2019 14:48:21 -0700 (PDT) Date: Thu, 8 Aug 2019 22:48:18 +0100 From: Stephane Chazelas To: Aryn Starr Cc: zsh-workers@zsh.org Subject: Re: Possible :q quoting bug Message-ID: <20190808214818.fmfzcyqvzjtrmkpr@chaz.gmail.com> Mail-Followup-To: Aryn Starr , zsh-workers@zsh.org References: <5E224043-AA93-4B39-94BB-6230A9A2737F@icloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5E224043-AA93-4B39-94BB-6230A9A2737F@icloud.com> User-Agent: NeoMutt/20171215 2019-08-08 20:36:00 +0430, Aryn Starr: > I expect this function to be idempotent on the command line: > ``` > Function reveal() { > eval “${@:q}” > } > ``` > But it’s not. It loses empty args. > I have written the following function to fix this ‘bug’: > ``` > gquote () { > local i > for i in "$@" > do > test -z "$i" && print -rn "''" " " || print -rn -- "${i:q}" " " > done > } > ``` You may want to use: reveal() eval "${(qq)@}" which is the zsh way to do it. $var:q is reminiscent of tcsh's $var:q though works differently (in tcsh, you do need cmd $var:q to pass the content of $var literally to cmd as tcsh has a completly fucked-up way of handling parameter expansions (hardly improved from the Thompson shell's simplistic parameter expansion from the early 70s). But like zsh's, tcsh's $var:q expands to nothing when $var is empty or a list of empty elements. Of the various ${(q)var}, ${(qq)var}, ${(qqq)var}, ${(qqqq)var} ${(q+)var}..., ${(qq)var} is the only one that is localisation-safe as it always using single quotes. The other ones (and also the quoting operators of other shells or of various printf %q) are generally not safe as they may quote some characters with \ (or use things like $'\n') and the encoding of \ is found in the encoding of some multi-byte characters in some locales. Note that mksh added a ${var@Q} which was later copied by bash. Initially, ${empty@Q} expanded to nothing (and it still does in bash), but that changed at some point in mksh where it now expands to ''. (possibly bash will follow). I'd agree zsh's documentation is misleading though as it currently says: q Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval. -- Stephane