From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1216 invoked by alias); 14 Jan 2017 21:00:14 -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: 22386 Received: (qmail 3276 invoked from network); 14 Jan 2017 21:00:14 -0000 X-Qmail-Scanner-Diagnostics: from out2-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.26):SA:0(-0.7/5.0):. Processed in 0.405843 secs); 14 Jan 2017 21:00:14 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= mesmtp; bh=1KwOv9nWtpeP3kTHA5574kaGhos=; b=TET7HmQrqoeMJgVWB9v2F R72oZ8ybxEZcQxpw4uV/7UzGpOsC9xZLxTjKUp3Wn9hFDEtLs5S7aq74Hk5JOm4/ YkfQTT3EMhrrQKoBSiavXRGB2DGAWpQJyQOZ8ARvounDA5LUP0LOoigQfKZbWV6W iauZBa/DF9O0mjHcDM3e5o= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=1KwOv9nWtpeP3kTHA5574kaGhos=; b=guF4HmDAiuRc33GPpZOC SzzofXbGuNUmvNDdKaMs7VAlWothSh8c7wwxuuq85+P3ype/wAk5MhpdetHywLRT owzvGAYEXKek989UrH8B17jH9wP/iOrUaBHUFMStniNQGg59AcTK3RWATraTYvIV hOaN+kxgrnjFBDPhW00FEkM= X-ME-Sender: X-Sasl-enc: A7n1gULej4kFng88pLRrf1bII2e+f8GkjAi/UnYOHK3K 1484427610 Date: Sat, 14 Jan 2017 20:56:41 +0000 From: Daniel Shahaf To: Ray Andrews Cc: zsh-users@zsh.org Subject: Re: whence question Message-ID: <20170114205641.GB6210@fujitsu.shahaf.local2> References: <652bcc3f-7365-2e52-d39c-8576278606bc__74.9235078275845$1484367323$gmane$org@eastlink.ca> <20170114044044.GA4002@fujitsu.shahaf.local2> <4981e434-473a-4dca-5d03-fea2e3051c1b@eastlink.ca> <63d2b432-4ca9-0e85-014c-333cb0f46836@eastlink.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Ray Andrews wrote on Sat, Jan 14, 2017 at 11:51:08 -0800: > On 14/01/17 10:55 AM, Bart Schaefer wrote: > > > > local _args=( ${~@} ) > > > > > [...] I almost read that one. What you wrote is: |local _args=`eval echo $@`|| ||_args=( ${(z)_args} )| Your input here was the positional arguments ($@), which are a list of words parsed from the command line. The input to eval is an unparsed command line string. Therefore, passing $@ to eval is a type mismatch. It will cause filenames with spaces to be split. The way to interpolate variables into eval's arguments is with (q), e.g., the following are equivalent: . echo $foo eval echo ${(q)foo} Next, using 'echo' will not safely round-trip arbitrary values; filenames with spaces or backslashes would be mangled by it (even without 'eval'). There are other problems here (splitting on spaces is the least of your concerns with that 'eval'; it inteprets data as code), but circling back to Bart's solution, what it does right is that it uses the correct data types and applies the correct transformation. That's because «${~@}» happens to be a transformation that takes a "$@", interprets every word in it as a glob, and returns a list of words. (Without the round parentheses, it'd return something else.) It's documented in "Parameter expansion" in zshexpn(1); grep for GLOB_SUBST. Note also that the round parentheses are required, to declare an array rather than a single string. Cheers, Daniel