From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4529 invoked by alias); 24 Nov 2014 17:23:04 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19427 Received: (qmail 29093 invoked from network); 24 Nov 2014 17:23:02 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f4-b7f126d000001e9a-c1-5473696a90f9 Date: Mon, 24 Nov 2014 17:22:49 +0000 From: Peter Stephenson To: Zsh hackers list Subject: Re: ${^var} and word splitting Message-id: <20141124172249.53419bd7@pwslap01u.europe.root.pri> In-reply-to: <141124085508.ZM16833@torch.brasslantern.com> References: <20141124095637.GA5716@chaz.gmail.com> <20141124111201.161d8cf2__23261.8202259347$1416827641$gmane$org@pwslap01u.europe.root.pri> <20141124152628.GA5749@chaz.gmail.com> <20141124155524.0739b3ec@pwslap01u.europe.root.pri> <141124085508.ZM16833@torch.brasslantern.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjluLIzCtJLcpLzFFi42I5/e/4Fd2szOIQg7cNlhY7Tq5kdGD0WHXw A1MAYxSXTUpqTmZZapG+XQJXxuML+5kLHgtUPFh0i7WB8TJPFyMnh4SAiUTzy/0sELaYxIV7 69m6GLk4hASWMkqs+rKbHcphktjy/jkrSBWLgKpE75q7YDabgKHE1E2zGUFsEQENiSl7d4LZ wgLqEm3P+8BqeAXsJbbe/QG2gVPASuLBswtMEEPnMUlM33werIFfQF/i6t9PTBBn2EvMvHKG EaJZUOLH5HtgzcwCWhKbtzWxQtjyEpvXvGWewCgwC0nZLCRls5CULWBkXsUomlqaXFCclJ5r qFecmFtcmpeul5yfu4kREoZfdjAuPmZ1iFGAg1GJh/dHT2GIEGtiWXFl7iFGCQ5mJRFe5rTi ECHelMTKqtSi/Pii0pzU4kOMTBycUg2MFR9WdVjubCpy9Omev2C9d+TZCdrnfdi5jQ93vba7 Z/MykXXVFZElIfVMZyIvLjurUFFrVzfPatlGjfqQVPvFTFuDC8zZSpf/6vzmNsEl56rNOZF/ phVLneu8d+4TywhK3Nt/OurQ+vWJq14v3NEaKXLHac5Wnezca9GS2WZrZOWelH7kC7uvxFKc kWioxVxUnAgAvbk3HSECAAA= On Mon, 24 Nov 2014 08:55:08 -0800 Bart Schaefer wrote: > On Nov 24, 3:55pm, Peter Stephenson wrote: > } Subject: Re: ${^var} and word splitting > } > } On Mon, 24 Nov 2014 15:26:28 +0000 > } Stephane Chazelas wrote: > } > If I understand correctly, in zsh the removing of those are > } > accounted to null-removal in things like: > } > > } > $ print -l $=a > } > 1 > } > 2 > } > 3 > } > > } > But then it's not clear why they are removed there and not in: > } > > } > a=':a::b:' > } > IFS=: > } > print -l $=a > } > } I looked at the code and you're exactly right: it's not clear. > > Isn't it always the case that *whitespace* in IFS is treated differently > than non-whitespace? E.g. consecutive whitespace is treated as a single > character, so (IFS=" " "a b") is two words but (IFS=: "a::b") is three? Yes, that's right, but what zsh is doing is a bit funny: as Stephane notes, in other shells you don't get the null arguments in the first place if the special whitespace rule is being followed, it's not a question of whether they get removed later or not. At least I think so --- splitting is implicit in other shells so I may just not be quite doing the equivalent. Here's what I did in bash: $ fn() { local arg; for arg in "$@"; do echo $arg; done; } $ fn2() { fn $1; } $ fn2 ' a b c ' a b c $ So that $1 argument to fn2 gets split in the way we're talking about, while within fn we make sure we pick up every piece that's been split from it. This definitely looks different from zsh. However, I think what you mention is indeed the source of the difference Stephane noticed, because doubling a whitespace character in IFS does have the documented effect of making it work the other way (see the zshparam manual; this is without the patch which is obviously not a correct fix): % a=' a b c ' % print $=a a b c % print -l $=a a b c % IFS=' ' # two spaces % print -l $=a a b c % So that explains the mysterious allownull whatever the explanation for the implementation. pws