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=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 8149b1c5 for ; Fri, 9 Aug 2019 11:01:32 +0000 (UTC) Received: (qmail 4619 invoked by alias); 9 Aug 2019 11:01:23 -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: 44647 Received: (qmail 9752 invoked by uid 1010); 9 Aug 2019 11:01:23 -0000 X-Qmail-Scanner-Diagnostics: from st43p00im-ztfb10071701.me.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(17.58.63.173):SA:0(-4.3/5.0):. Processed in 1.674696 secs); 09 Aug 2019 11:01:23 -0000 X-Envelope-From: whereislelouch@icloud.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at icloud.com designates 17.58.63.173 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1565348446; bh=N4PnYjBUFi5uALws9wGRiP5SZOFYk/DdmYHeTJ2lGIE=; h=From:Message-Id:Content-Type:Subject:Date:To; b=tXe0GteN2Wh8lrWmAmdg6ePdX1Eek2nmKehLozb53oZ2sps/w/Ew9tb1LnTn6N4kN guALq4YhHECwqvulADWo58YTskvwwslKbjcP8zwAKTkLDr9QMZ2KIn1+g+zOMSei4f DCw661e0FR3xTFBesyIlT5gwPNV3gUHesRkBKKQudyejUegG4Y2llKarR4jYyP+ou0 SmNs5j6Pxse83mrnHinAbqM4xb/Fhe8gPZLT4UW4qcIw/LE7wFC3+oEw6yORS4YZY0 2nxCDlhJLBEB/1D65e7IJsGf2OM4gTsCZ0UvoBKMEMyi6tDcdaDQdrklJjGTktnGJ0 togzryNJmFo5g== From: Aryn Starr Message-Id: <37789068-9DCE-4B80-9C99-CEA8621F2895@icloud.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_274E0324-4C36-48B0-9A95-FB66F25B7857" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: Possible :q quoting bug Date: Fri, 9 Aug 2019 15:30:40 +0430 In-Reply-To: <20190808214818.fmfzcyqvzjtrmkpr@chaz.gmail.com> Cc: zsh-workers@zsh.org To: Stephane Chazelas References: <5E224043-AA93-4B39-94BB-6230A9A2737F@icloud.com> <20190808214818.fmfzcyqvzjtrmkpr@chaz.gmail.com> X-Mailer: Apple Mail (2.3445.104.11) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-08-09_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1812120000 definitions=main-1908090113 --Apple-Mail=_274E0324-4C36-48B0-9A95-FB66F25B7857 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Thanks! I suggest adding this little tidbit to the manpage. I tested `=E2=80=9D${(q@)@}=E2=80=9D =E2=80=9C${(q)@}=E2=80=9D = =E2=80=9C${(qq@)@}=E2=80=9D`. The only one to actually be idempotent (on = my English locale at least) is `=E2=80=9D${(q@)@}=E2=80=9D. If you use = `=E2=80=9D${(qq@)@}=E2=80=9D, you=E2=80=99ll lose aliases, which can be = dangerous, when, e.g., you have aliases `rm` to `rm -i`. (Though = generally I use aliases as little functions.) > On Aug 9, 2019, at 2:18 AM, Stephane Chazelas = wrote: >=20 > 2019-08-08 20:36:00 +0430, Aryn Starr: >> I expect this function to be idempotent on the command line: >> ``` >> Function reveal() { >> eval =E2=80=9C${@:q}=E2=80=9D >> } >> ``` >> But it=E2=80=99s not. It loses empty args. >> I have written the following function to fix this =E2=80=98bug=E2=80=99= : >> ``` >> gquote () { >> local i >> for i in "$@" >> do >> test -z "$i" && print -rn "''" " " || print -rn -- = "${i:q}" " " >> done >> } >> ``` >=20 > You may want to use: >=20 > reveal() eval "${(qq)@}" >=20 > which is the zsh way to do it. >=20 > $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). >=20 > But like zsh's, tcsh's $var:q expands to nothing when $var is > empty or a list of empty elements. >=20 > 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. >=20 > Note that mksh added a ${var@Q} which was later copied by bash. >=20 > 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). >=20 > I'd agree zsh's documentation is misleading though as it > currently says: >=20 > 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. >=20 >=20 > --=20 > Stephane --Apple-Mail=_274E0324-4C36-48B0-9A95-FB66F25B7857--