From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-users@zsh.org
Cc: Leander Jedamus <ljedamus@googlemail.com>
Subject: Re: possible bug in zsh concerning a for loop
Date: Fri, 18 Mar 2022 17:45:22 +0900 [thread overview]
Message-ID: <646DEC1A-CEC9-47B7-9D90-954D213C25B5@kba.biglobe.ne.jp> (raw)
In-Reply-To: <ef02682f-2d96-4c7e-1d02-0d6a836b1f21@gmail.com>
> 2022/03/18 16:33, Leander Jedamus <ljedamus@googlemail.com> wrote:
>
> items="item1 item2 item3"
>
> for i in $items; do
> echo "\"$i\""
> done
> This prints:
> "item1 item2 item3"
This is not a bug but a feature of zsh.
Yes, it is incompatible with other shells (sh/ksh/bash ...),
and one of the most significant incompatibilities.
See 'man zshexpn' and search for SH_WORD_SPLIT.
> It should print:
> "item1"
> "item2"
> "item3"
You can get this by:
[1] use array (instead of scalar parameter items)
a=( item1 item2 item3 )
for i in $a; do ... done
[2] use ${=items}
for i in ${=items}; do ... done
[3] set SH_WORD_SPLIT option
setopt SH_WORD_SPLIT
for i in $items; do ... done
I prefer [1], but it is up to you which method you use.
next prev parent reply other threads:[~2022-03-18 8:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-18 7:33 Leander Jedamus
2022-03-18 8:45 ` Jun T [this message]
2022-03-18 14:14 ` Vincent Lefevre
2022-03-18 8:21 Leander Jedamus
2022-03-18 10:12 Leander Jedamus
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=646DEC1A-CEC9-47B7-9D90-954D213C25B5@kba.biglobe.ne.jp \
--to=takimoto-j@kba.biglobe.ne.jp \
--cc=ljedamus@googlemail.com \
--cc=zsh-users@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).