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, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17977 invoked from network); 22 Aug 2022 07:59:51 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 22 Aug 2022 07:59:51 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1661155191; b=G2FNQ7pJa88LcrujKK8TTQ30pCMcJ2O1AjHAIt6aHBPdEi7vSE9Njn7722fjROiKQShN5t0mLA JS1hVwyBn7UR0vP4gQSAyIZr3Vh8nzXLlnpaHBpDYqM6nMZKpl7x94zMTtGjMk3UqTlbxHYygk 6GMBEY7+KE6/JiUcEgL4t4cOa27/WtGDqcWFJlwNPQVpMG5xLIdYHLzWbhSvGmjFnAyb9KqnHc ZyDPPoD7twZihy9mdVvBcPIrXvn9couHRwcWQ6pVzRHShL73uUMBSr8Md3D0mXL1gL0TK4NDbP /+rFFudxkB+HhKGjPHpJmatF7xmsaMvX0D61bTBzkY4spQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-vs1-f54.google.com) smtp.remote-ip=209.85.217.54; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1661155191; bh=kUwXGOCn7A7kCMKwwdjAnLtBM+plxE7XAko+nnnJiSs=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=X3Qhm8O+m9M8vz7zavypDL29yXwvGEj7UPV8na4GiV5xbKBOjJfJVnGu8XoDhWyBnZQoM7T4NJ GamHpJY/MmLysHoe5GgFhaWxErbaOBifCuYPCqeiiyFGuKvnYWDTsmTyCVx2I9bQTeWYeFb1nX DxWNNrf7OXdTqBcjE7lR5kvr4la6EGLfKU2WjBOebYtXbzbSe/BgW8D14S4vOUTZ5rAFDIIEP1 GE71s9YhTGi87QcYlDS7Diw/hZgnMiSI0NbcnBwQHSOPWAuMR/EtFowC3OYH+HGtp3o5Tzd/Sd 2RgFHcfm34BsZN5mDuGE17lEVN17+zLdDQDMFHoVI/46rg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=yMfpypGTIXjYPja8cZ++Cuig3bt+j23upinA7k59KDU=; b=XYIo7on1Tmz4jUkJuFToyXiPYX E6I7ACDYsfIoSoPG6n1NF4Czwrz2OfJcrZefmmS0cHZ8NTwtcUZ5EesUdfyQkWbCZV8GUnR5r5Dj8 XEonOfBqyM9tedT/euuLt24uvp1W8/CrxuI7AJQdaXfSOODfy4jYb7xmV18F15qhc/pUofNSKfdKu gBVGkzWRjdnvl4CLb2lNoOQklvJUu+AKoSi6oIfk+zhVm/H6VYRaABTfFUjA7RDl1yv8CCLcGIlqs Ejx6ZYnFFBsci9+XvYBrC+rpmPLVtvpmFfM2s1nUjWhmb5RSubUaWH+Ec5fwplBNlb4wVWsFi3QFw ZUAaFJFA==; Received: from authenticated user by zero.zsh.org with local id 1oQ2Le-0003WP-0q; Mon, 22 Aug 2022 07:59:50 +0000 Authentication-Results: zsh.org; iprev=pass (mail-vs1-f54.google.com) smtp.remote-ip=209.85.217.54; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-vs1-f54.google.com ([209.85.217.54]:46074) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1oQ2GW-00035D-BF; Mon, 22 Aug 2022 07:54:33 +0000 Received: by mail-vs1-f54.google.com with SMTP id m66so10227092vsm.12; Mon, 22 Aug 2022 00:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=yMfpypGTIXjYPja8cZ++Cuig3bt+j23upinA7k59KDU=; b=fCNv5gCwOocArk3ylh4MowLXl2xa4nez+NxS9TIrExADCL+NIAnKtXGxhkgQhxFSAP DtES7dmTEe0zm1r2yvmm9lwFvI419qyOCvKaMTNLfA0THBOWfalT5Kt072NYj5JPh7iu ccDsHhmHqHye5zXRJ/czYrWuGSy3OGxElYJhRH+aNzcFPIrnzO2flh5GWfGc3E02jW4Q xgaMLTIPfNM00aB3T43eyq3M6rIIhNyAeDinT/BSI20St1S0JV0T/U3yR69vNuRUWo5D AoWxBEPcRuwbkn+okCvkMgdZYJtuMNsYmuKbdHbcY0v+DpyvHIOQB0ene5OD3XCMNJQ+ HHjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=yMfpypGTIXjYPja8cZ++Cuig3bt+j23upinA7k59KDU=; b=Rd8dmctmZQiyPApxkYV1TgkbYrtpQk8UfaAp4qgNA6/Tw2pEoRWUN2YXWlOyEKNXZn F1IIxD9b4OvzkMabesx9AU+Dauzk2ondlswE9wBDQ6kM5MA608cFgIdV3TKNWm0Akbqg h548mhzbcXXrwYy7M6aG71XGXS25c2/NwC2iErKUEC8EKGPySMAxpoc1VDTM2fkAxKlK zDFJFZ5nscQILn7gmex3OiJa5hD8SaykO3ZVoA20tYBv4hoXNjkMP8XOL5ZUz8o8ZcCc 2fGCl4Ghc5v57tkd619xH3WXVYfqKNXvcPhY5rJMyxgLvAKXPSuhdeugSYEki8iUTmgv 4l8g== X-Gm-Message-State: ACgBeo3qwZSQFYzH3AeFnMmcSgC47OQy1kLozF51uMR041n/7G3w9EFu oPPjcLGSFjm3DdEk6T/bWBzQqGBKQKIfXdQS0lKVLwo2AFw= X-Google-Smtp-Source: AA6agR6s54iklG1jSkPGcxL4DCU6ZQg1i7jnyve+tdQSNQgVOrdrRjkkO/rFeyiIa/Ho0XeLtKLwhD4yTwhvNj/Vv1M= X-Received: by 2002:a05:6102:5591:b0:38a:9691:933f with SMTP id dc17-20020a056102559100b0038a9691933fmr6252056vsb.54.1661154870645; Mon, 22 Aug 2022 00:54:30 -0700 (PDT) MIME-Version: 1.0 References: <605183ae-f347-4f64-bf99-e89f98b6637e@www.fastmail.com> In-Reply-To: <605183ae-f347-4f64-bf99-e89f98b6637e@www.fastmail.com> From: Liu Xin Date: Mon, 22 Aug 2022 00:54:19 -0700 Message-ID: Subject: Re: An incompatible behavior from bash? To: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= Cc: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary="000000000000fb57bb05e6cfc1e6" X-Seq: 50494 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: --000000000000fb57bb05e6cfc1e6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Lawrence, I hold the wrong impression that zsh is compatible with bash. I just assume it because I see both Ubuntu and MacOS have replaced bash with it. Thank you for your explanation. Indeed, it uses letter l as a word modifier (14.1.4 Modifiers). I will read the zsh manual! thanks, --lx On Fri, Aug 19, 2022 at 5:40 PM Lawrence Vel=C3=A1zquez wr= ote: > On Fri, Aug 19, 2022, at 6:32 PM, Liu Xin wrote: > > I think zsh is compatible with bash > > It is only partially compatible, and compatibility is not a development > priority. The notion that zsh is a fancy superset of bash is false; > zsh will only run simple bash scripts correctly. (Whether it errs > loudly or quietly depends on the feature used. Using sh emulation > may also help.) > > You are better off assuming that an arbitrary bash feature *does > not* work with zsh unless proven otherwise, rather than assuming > that it *does* work. > > > but I found one different behavior > > in parameter expansion. In the following example, I guess zsh > > interprets "$1:l" as a whole. Is it intentional? > > Yes. From the documentation you linked: > > In addition to the following operations, the colon modifiers > described in "Modifiers" in "History Expansion" can be > applied: for example, ${i:s/foo/bar/} performs string > substitution on the expansion of parameter $i. > > [...] > > ${name} > The value, if any, of the parameter _name_ is > substituted. [...] In addition, more complicated > forms of substitution usually require the braces > to be present; exceptions, which only apply if the > option KSH_ARRAYS is not set, are a single subscript > or any colon modifiers appearing after the name > [...]. > > Your example applies the "l" history modifier, which converts the > expansion to lowercase. This is more obvious with a different > choice of value: > > % export VAR=3DHELLO > % zsh -c 'echo "$VAR:l"' > hello > > Braces are required if KSH_ARRAYS is set (either explicitly or via > sh/ksh emulation). > > % zsh --emulate sh -c 'echo "$VAR:l"' > HELLO:l > % zsh --emulate sh -c 'echo "${VAR:l}"' > hello > > -- > vq > --000000000000fb57bb05e6cfc1e6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi, Lawrence,

I hold the wrong impression that zsh is compatible with bash= . I just assume it because I see both Ubuntu and MacOS have replaced bash w= ith it.
Thank you for your explanation. Ind= eed, it uses letter l as a word modifier (14.1.4 Modifiers). I will read th= e zsh manual!

thanks,
--lx



On Fri, Aug 19, 2022 at 5:4= 0 PM Lawrence Vel=C3=A1zquez <larryv@z= sh.org> wrote:
On Fri, Aug 19, 2022, at 6:32 PM, Liu Xin wrote:
> I think zsh is compatible with bash

It is only partially compatible, and compatibility is not a development
priority.=C2=A0 The notion that zsh is a fancy superset of bash is false; zsh will only run simple bash scripts correctly.=C2=A0 (Whether it errs
loudly or quietly depends on the feature used.=C2=A0 Using sh emulation
may also help.)

You are better off assuming that an arbitrary bash feature *does
not* work with zsh unless proven otherwise, rather than assuming
that it *does* work.

> but I found one different behavior
> in parameter expansion.=C2=A0 In the following example, I guess zsh > interprets "$1:l" as a whole. Is it intentional?

Yes.=C2=A0 From the documentation you linked:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 In addition to the following operations, the co= lon modifiers
=C2=A0 =C2=A0 =C2=A0 =C2=A0 described in "Modifiers" in "His= tory Expansion" can be
=C2=A0 =C2=A0 =C2=A0 =C2=A0 applied: for example, ${i:s/foo/bar/} performs = string
=C2=A0 =C2=A0 =C2=A0 =C2=A0 substitution on the expansion of parameter $i.<= br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 [...]

=C2=A0 =C2=A0 =C2=A0 =C2=A0 ${name}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 The value, if any, = of the parameter _name_ is
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 substituted.=C2=A0 = [...]=C2=A0 In addition, more complicated
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 forms of substituti= on usually require the braces
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 to be present; exce= ptions, which only apply if the
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 option KSH_ARRAYS i= s not set, are a single subscript
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 or any colon modifi= ers appearing after the name
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 [...].

Your example applies the "l" history modifier, which converts the=
expansion to lowercase.=C2=A0 This is more obvious with a different
choice of value:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 % export VAR=3DHELLO
=C2=A0 =C2=A0 =C2=A0 =C2=A0 % zsh -c 'echo "$VAR:l"'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 hello

Braces are required if KSH_ARRAYS is set (either explicitly or via
sh/ksh emulation).

=C2=A0 =C2=A0 =C2=A0 =C2=A0 % zsh --emulate sh -c 'echo "$VAR:l&qu= ot;'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 HELLO:l
=C2=A0 =C2=A0 =C2=A0 =C2=A0 % zsh --emulate sh -c 'echo "${VAR:l}&= quot;'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 hello

--
vq
--000000000000fb57bb05e6cfc1e6--