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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, FREEMAIL_FROM,MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 3476 invoked from network); 25 Jul 2021 03:31:15 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 25 Jul 2021 03:31:15 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1627183875; b=flTNM71yv/dXzqS8nldiQrEV98EGKplWtg3KfBwX4xWxfTkF1IyIfuWrenZzWvDE0F7hfxAjP6 OLdur5MwYx/tL8y/rOCPuGu3TeQPAxsdIsIhNS3KI/+p6KLV8y11oWvOm+AclW4MG4BnrBIB+J WOc+wiVwVmhO8WB8Nu/8qedJoALUmnb7+DJZYD9rLl7l7F6iqjLP6IRZpmLAjSwOvlh5/ZOI7D g/5ziTg4GbjPsVoChf9q8gaIKXXJ5fdhYcrTtpjlNrvrnnmrf96nkczlLsxglHhtsE/IKm3ODi gK5ltrff93AgE4M4CiexxRgDCaJRDu3vuXePHyrZ5YahAA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mout.gmx.net) smtp.remote-ip=212.227.17.20; dkim=pass header.d=gmx.net header.s=badeba3b8450 header.a=rsa-sha256; dmarc=none header.from=gmx.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1627183875; bh=p5K7+1l/gb6INEnlcIxRoKl4/SwAdCZJcJcCK2mEeaM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:To:Subject:DKIM-Signature: DKIM-Signature; b=xb5C2Cf24g4H5JpVHwohoxMsl7pNGcCLBFxxCK1wwznDqYCazDsVDdnDok2jf0nEPoIlaCIBcJ lDApQV2l/5GCtkXm0YpnpV8zsZUdjwBheXmqLN/iwNfhPJlokgDzXerUYSGKBIwKy1klQujgUo na711CyLovJzDyO01Iawe5YIvAbomyELSmtTQH7QahMrcF1S8yBqhqxajvY6ObH9K9ytOPH6RI /obsVkzez46STf+hQ6LAOM3LFKL3LS//g9A42ap2sxjikn6S4T9GPvAKrHJBH9ExIVxi17U6LE fmyQKReB1AOi7TKqwGDRk/wLal+YKjgfDbLNA5w/uZaBTg==; 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-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:To: Subject:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=+uLf3eDhD4Cr57jFe1m1F4d7gr67k9yxKjXpUuGS4EM=; b=1H3VEZHYNOphosJo1OVDCXxwSD vWY3kZPZUETKGup4SOEnNxNTw35DY7us+9yRGjwSOE9Zd/ZPL3fmC3QPXcwhWslO67gSWSu40b5Gp OPU3xO6ThcdW2p+lAGgoH6Yiagh1m4+SOgFeT+/XSnq/ctDC0N3+Nzfny/whXX3kyrgSAnxv91ANw 9lLHLKSgwaKa0aoXiK36jI8g/UZdY9iDt5Z4rjivzp3b4cq7ti8P0OIytackEmNSbw2+cBOBltoTi +mSFc0hZhIhtBYxB01gul8bBKVriSm4GPde7yQl7CER5/gy0lggbCwmp03XedbPC+XHa/QVlfoxwE 4AnANHzg==; Received: from authenticated user by zero.zsh.org with local id 1m7UrC-000B9h-JB; Sun, 25 Jul 2021 03:31:14 +0000 Authentication-Results: zsh.org; iprev=pass (mout.gmx.net) smtp.remote-ip=212.227.17.20; dkim=pass header.d=gmx.net header.s=badeba3b8450 header.a=rsa-sha256; dmarc=none header.from=gmx.com; arc=none Received: from mout.gmx.net ([212.227.17.20]:32833) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1m7UqT-000ASl-8N; Sun, 25 Jul 2021 03:30:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1627183828; bh=p5K7+1l/gb6INEnlcIxRoKl4/SwAdCZJcJcCK2mEeaM=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=DcccyqB7y5PTwFDGK9JVLZduOXWL8DQ2txcmpL25kq/At6SpIl31vH8aYC8z5nIAV 5uZ7/ntx9xcQussvvL+ob8ma8/xCg2S7sVjNhqLq2Kv8np6j0PERSjh07PCNImQp6G uwcXz1LI9KTuhDe/MDo2KnN7V7YAMNLj823qlK/Y= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from caerleon-medb.mac-anu.org ([71.227.85.179]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1M2f9b-1m514e3Oql-004Db3 for ; Sun, 25 Jul 2021 05:30:28 +0200 Subject: Re: CONDITIONAL EXPRESSIONS, string == pattern To: zsh-users@zsh.org References: From: Eric Cook Message-ID: <45ef93bd-148b-54fc-9815-5b5dbe71d1f0@gmx.com> Date: Sat, 24 Jul 2021 23:30:26 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:1k3AmTL3ZZhuOXCd92TyVXfh2HxIwDLpWorOAvXwShOKzFYmDGW 7Muciv+3VWViO6srK1JbB6qSSJ4u47L29FL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FI4kwA87R9VmACs6j5GD7qpDiakHmqlAInwCJdL1+2bBqyo0h/k7ObOYpKZ9 PO+W85QOfwZEy/SiVB/ankZdiJj2l7KhPFPmCoze21x7EpPGIZqk+2XenIsgQKbBVGKo7lLMX I+62OKdKlGgO30ijHZW9LQtErz1I2/SjqUNqgGXmOrqC/2Z3lkS0WvoCVdOwURaxNIBca+oCy A3vWTt7q2jQRa2ZKyhJkvMf9jaQQFZXQfjk X-Seq: 26806 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On 7/24/21 10:14 PM, scowles@ckhb.org wrote: > I would like to execute test on patterns that are dynamically generated = and that change between invocations depending on other data.=C2=A0 When I = generate a scalar parameter containing the pattern, construct the test sta= tement, then invoke it, the test fails. > However, if I force an eval on the test statement, the test succeeds.=C2= =A0 I do not understand zsh parsing in this case.=C2=A0 Could someone plea= se let me know the mechanics I am missing? > > thanks very much. > > zsh version:=C2=A0 5.8, patch 460 > platform:=C2=A0 x64, ubu 21.04, current patches > > # test code begin: > > unset vs vp r > local -a r > > vs=3D' str1=C2=A0 a2' > vp=3D > vp+=3D[[:blank:]]## > vp+=3Dstr1 > vp+=3D[[:blank:]]## > vp+=3D[[:alnum:]] > vp+=3D[[:alnum:]] > > r=3D( ${(f)"$( eval echo 'test ${vs} =3D=3D ${vp} && echo hi || echo lo'= )"} ) > echo ${r[-1]} > > test ${vs} =3D=3D ${vp} && echo hi || echo lo > > # test code end. > > first test output:=C2=A0=C2=A0 hi > second test output:=C2=A0 lo > Your code assumes EQUALS is disabled which allowed test =3D=3D to not erro= r with a command not found error. so in: eval echo 'test ${vs} =3D=3D ${vp} && echo hi || echo lo' zsh does the normal expansions of the line and passes the arguments to eva= l, since the single quotes prevented any possible expansions the result is: echo test ${vs} =3D=3D ${vp} && echo hi || echo lo so the above line goes through the steps of expansions and ends up like so= : echo test ' str1 a2' '=3D=3D' '[[:blank:]]##str1[[:blank:]]##[[:alnum:]][= [:alnum:]]' && echo hi || echo lo so /echo/ prints out the strings given to it, which succeeds, causing echo= hi to run. Nothing related to pattern matching happened since test doesn't perform pa= ttern matching. CONDITIONAL EXPRESSIONS A conditional expression is used with the [[ compound command to t= est attributes of files and to com=E2=80=90 pare strings. Each expression can be constructed from one or m= ore of the following unary or binary expressions [[ does perform pattern matching on its right hand operand but when said p= attern is inside a parameter you have to perform an expansion that allows for it to be treated as a pattern sinc= e the results of a parameter expansion are treated literal unlike other shells. ultimately, the script boils down to: setopt extendedglob unset vs vp r vs=3D' str1 a2' vp=3D[[:blank:]]##str1[[:blank:]]##[[:alnum:]][[:alnum:]] if [[ ${vs} =3D=3D ${~vp} ]]; then echo hi else echo lo fi