From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-return-43594-ml=inbox.vuxu.org@zsh.org 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_ADSP_CUSTOM_MED, 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 24b10041 for ; Thu, 4 Oct 2018 15:45:30 +0000 (UTC) Received: (qmail 18822 invoked by alias); 4 Oct 2018 15:45:04 -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: 43594 Received: (qmail 13684 invoked by uid 1010); 4 Oct 2018 15:45:04 -0000 X-Qmail-Scanner-Diagnostics: from mail-vk1-f177.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.221.177):SA:0(-1.9/5.0):. Processed in 2.495103 secs); 04 Oct 2018 15:45:04 -0000 X-Envelope-From: rotogluon@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=j8SmjAC429Vdbo01mLqIdXQ2cXIknSjt/9H8QTjKxxc=; b=ciCCZ+IJQT9nzJQBHXKhTcvbuH17k8C9Pduf/jjqLSX7nZd3d3cbKFf7UX0jR8/ItI o0S3ASrwTaWUjHRhIR5zxQic5c7HA0s0Qru56/j7HFMFepS3tfYL+PHnustcAVYcJSLy /cP2SJ/E+1fUkqy3UNM8tbWuHVu0ZytfXPq0AMogS+1PiXHI0gjWXvbA4XNlIINtNYWa hrUqTWiijgmHfpbWdVrOvNWBmMmDYsk2ZdOcnus7TarNP/2dBwBixrifXm0OUmFn8Cwi Jv3KjYfW2yyRwNt3/hpDfUHHu72ytYfN+xzy4DzrNO1gq8QjzYO68RxEoRX2WsM2fMVI 83hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=j8SmjAC429Vdbo01mLqIdXQ2cXIknSjt/9H8QTjKxxc=; b=pfP1q1+VtDI830weElsRfugoXH0PR1pl+QKWyqWQbI26nm/Aj6eWXJp7DjC7k7ZZ0h PDs9RyMsZDazMP+BmNmc7JdMkKtzEmU4J+2SM+eRvFvGYFw4b5+AnGacXmuDEbe2t3nH KQJo9v7rj/hifc2VxEJZIUzclDTRnSs88L2W2d2yXFT7+maD0fWkoJIAhBQb2E9pzMhY blb88Gw7jtSBybzN9VRqG8JDsvcyd5QCCIMXY0uzZ9ABQLH4IlFZR2rgZY4fbbZrMyhs qCD7RbWoK4WPTsYzSlEp9HSihP5Fswuut1cQUekyeoxA5myUhRqXv0h48wGlgLfvK7lf mT6A== X-Gm-Message-State: ABuFfoinknnRMEfcZR1aSa/wXLnzzQkYdai8Nt2sC1VuQ4VBbGrLF4xS lJhv4/8oldba3fnXjvLgMi3r42S45NBbwNCxmZ0gn8Av3AfzFw== X-Google-Smtp-Source: ACcGV63hw2pUZP1es/F/JZ3tjY32FOSjwUtUXQnoodM8BYaE//0A+sf2Mz+gvkuvFgr998OyO+NIMiT4T1wxGag6V6Q= X-Received: by 2002:a1f:a210:: with SMTP id l16-v6mr2867470vke.38.1538667897061; Thu, 04 Oct 2018 08:44:57 -0700 (PDT) MIME-Version: 1.0 From: =?UTF-8?Q?Cl=C3=A9ment_BARRET?= Date: Thu, 4 Oct 2018 17:44:45 +0200 Message-ID: Subject: [ BUG ] Parameter expansion issue on a defined as an empty string variable, using the "NO UNSET" flag. To: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary="0000000000006e93df05776909e6" --0000000000006e93df05776909e6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, It appears there is a mix related to the colon use (which forces "set and not empty strings") and the special ":#" expansion type when using the "set -u" flag. Let's consider this example : #!/bin/zsh set -u; typeset youpi=3D""; echo "plop 1"; echo "youpi 1 ${youpi#*.cfg}"; echo "plop 2"; echo "youpi 2 ${youpi##*.cfg}"; echo "plop 3"; echo "youpi 3 ${youpi%*.cfg}"; echo "plop 4"; echo "youpi 4 ${youpi%%*.cfg}"; echo "plop 5"; echo "youpi 5 ${youpi:#*.cfg}"; echo "plop 6"; % ./test.zsh plop 1 youpi 1 plop 2 youpi 2 plop 3 youpi 3 plop 4 youpi 4 plop 5 ./test.zsh:15: youpi: parameter not set Here is the manual part of the zshexpn "parameter expansion" section : ${name#pattern} ${name##pattern} If the pattern matches the beginning of the value of name, then substitute the value of name with the matched portion deleted; otherwise, just substitute the value of name. In the first form, the smallest matching pattern is preferred; in the second form, the largest matching pattern is preferred. ${name%pattern} ${name%%pattern} If the pattern matches the end of the value of name, then substitute the value of name with the matched portion deleted; otherwise, just substitute the value of name. In the first form, the smallest matching pattern is preferred; in the second form, the largest matching pat=E2=80=90 tern is preferred. ${name:#pattern} If the pattern matches the value of name, then substitute the empty string; otherwise, just substitute the value of name. If name is an array the matching array elements are removed (use the `(M)' flag to remove the non-matched elements). The ":#" expansion type doesn't behave like the "#" one at all. If the "#" one matches, it can be the beginning of the string only while the ":#" pattern must match the whole string. Hence the colon here can't be considered as a modifier to tell whether you want or not "the emptiness" be checked or not. Here is another way to show this "colon" behavior : #!/bin/zsh set -u; echo "plop 1"; echo "youpi 1 ${youpi+defined}"; echo "plop 2"; echo "youpi 2 ${youpi:+defined and not empty}"; typeset youpi=3D""; echo "plop 3"; echo "youpi 3 ${youpi+defined}"; echo "plop 4"; echo "youpi 4 ${youpi:+defined and not empty}"; echo "plop 5"; echo "youpi 5 ${(M)youpi:#matches the whole pattern}"; echo "plop 6"; % ./test2.zsh plop 1 youpi 1 plop 2 youpi 2 plop 3 youpi 3 defined plop 4 youpi 4 plop 5 ./test2.zsh:17: youpi: parameter not set The workaround is to embed the parameter expansions like this : echo "${youpi:+${youpi:#my pattern here}}"; *BUT* this is really cumbersome and not documented at all in the manual. Some technical details : % zsh --version zsh 5.0.2 (x86_64-redhat-linux-gnu) % cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) I think there should be a fix here to apply the ":#" expansion even on the empty string and especially not raise an error while using the set -u option on a defined variable, ever... Regards, RotoGluOn --0000000000006e93df05776909e6--