zsh-workers
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <larryv@zsh.org>
To: "Liu Xin" <navy.xliu@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: An incompatible behavior from bash?
Date: Fri, 19 Aug 2022 20:39:53 -0400	[thread overview]
Message-ID: <605183ae-f347-4f64-bf99-e89f98b6637e@www.fastmail.com> (raw)
In-Reply-To: <CAHPdc0kc06epWceF-zLaoan-AdGyuDPept4Exd=T1Q7UPghseA@mail.gmail.com>

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=HELLO
	% 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


  reply	other threads:[~2022-08-20  0:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-19 22:32 Liu Xin
2022-08-20  0:39 ` Lawrence Velázquez [this message]
2022-08-22  7:54   ` Liu Xin
2022-08-22 21:44     ` Bart Schaefer
2022-08-23  5:42       ` Liu Xin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=605183ae-f347-4f64-bf99-e89f98b6637e@www.fastmail.com \
    --to=larryv@zsh.org \
    --cc=navy.xliu@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).