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,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24002 invoked from network); 13 Aug 2021 03:51:38 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 Aug 2021 03:51:38 -0000 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:Subject:Cc:To:From:Date: References:In-Reply-To:Message-Id: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=XIdr2t3rvxtgePxpiyeSYt+W/GUKCEdz6VZQ+/xmXJ4=; b=kOuz7qow7g7ZpHwz5g+dxl4UjL QNY6QdXNjEqwzIGUmKLcpAp49xMgdoRHY3KZgtsYOGhj2bW1exC0FJUE7IGW4+rWeSoD4J7/mNtMd lrtFt0gNHXLcVUYGKLeCt3/hGv0lZHsxtqvk9TuodymZgE3Sd4XDELQo2QdJH+9ihSfLsvxXCXZok jMTLb6Wifxw7Qx4U6Xj6ime4Yg/XzkLsTzxlG8EX1S5qvjFkElbV9iG2Dan3KAC8530mlygOgnnt9 4CKvvAilyn0SkN8h+VMwC/nxFPuEV2nShvDVIsVu9gi6H7ncEcL59NqlVZyXbn06sGREK8ZnwLeOn E4L13A8g==; Received: from authenticated user by zero.zsh.org with local id 1mEOEM-000I4L-1z; Fri, 13 Aug 2021 03:51:38 +0000 Received: from authenticated user by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1mEOE8-000HlB-HU; Fri, 13 Aug 2021 03:51:24 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id E2BC627C0054; Thu, 12 Aug 2021 23:51:22 -0400 (EDT) Received: from imap2 ([10.202.2.52]) by compute3.internal (MEProxy); Thu, 12 Aug 2021 23:51:22 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrkeeggdejhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderreejnecuhfhrohhmpefnrgifrhgv nhgtvggpgggvlhojiihquhgviicuoehlrghrrhihvhesiihshhdrohhrgheqnecuggftrf grthhtvghrnhepieekjeevledugeefiefgueelgffgtddtgeehvedvhedviefghedvffeu vddvueehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eplhgrrhhrhihvodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdduudehudek jeejtdegqdduudelvdejfeekhedqlhgrrhhrhihvpeepiihshhdrohhrghesfhgrshhtmh grihhlrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2E5D7A038A7; Thu, 12 Aug 2021 23:51:22 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-554-g53a5f93b7d-fm-20210809.002-g53a5f93b Mime-Version: 1.0 Message-Id: <34dbacca-01ee-4dda-a179-505c57760309@www.fastmail.com> In-Reply-To: References: Date: Thu, 12 Aug 2021 23:50:34 -0400 From: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= To: "Daniil Iaitskov" Cc: zsh-workers@zsh.org Subject: Re: bug: nested for loop body is executed once! Content-Type: text/plain X-Seq: 49279 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: On Thu, Aug 12, 2021, at 11:13 PM, Daniil Iaitskov wrote: > I just spot a following bug on Big Sur zsh 5.8 (x86_64-apple-darwin20.0) It's not a bug. > > $ K="1 2 3" > > $ for i in $(for j in $K; do echo "ddd/$j" ; done) ; do echo "$i" ; done > > ddd/1 > > 2 > > 3 > > I would expect following output > > ddd/1 > > ddd/2 > > ddd/3 By default, zsh does not word-split unquoted parameter expansions; this behavior differs from most Bourne-adjacent shells. Observe that your "inner" loop actually only loops once, with $j taking on the entire value of $K: % K="1 2 3" % for j in $K; do echo ""; done However, zsh *does* word-split unquoted command substitutions, so the output of $(for j in $K; do echo "ddd/$j" ; done) is split into 'ddd/1', '2', and '3', and $i takes on each value in turn. > > $ for i in $(for j in $(echo 1 2 3); do echo "ddd/$j" ; done) ; do echo "$i" ; done > > produce expected output: > > ddd/1 > > ddd/2 > > ddd/3 In this example, $(echo 1 2 3) is word-split because it is a command substitution. Thus, $j takes on the values '1', '2', and '3', as you expected. > I don't know if this is a feature due to some legacy optimizations. > I mostly use BASH and this behavior differs from BASH. > BASH behaves exactly as I expect. Actually, many zsh users consider the word-splitting of unquoted parameter expansions to be a misfeature, which zsh's default behavior remedies. In any case, it's very much intentional. You can obtain word-splitting behavior with the ${=foo} form: % K="1 2 3" % for j in ${=K}; do echo ""; done You can also set SH_WORD_SPLIT, or rewrite the code to use an array. If you're running code that relies on word-splitting (a POSIX script, perhaps), you can run it under sh emulation. > Wow! Are you still using just a mailing list for bug tracking?! Yes. -- vq