Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: whence question
- X-seq: zsh-users 22386
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Subject: Re: whence question
- Date: Sat, 14 Jan 2017 20:56:41 +0000
- Cc: zsh-users@xxxxxxx
- 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=
- In-reply-to: <ac84bfaa-5034-8465-1ce9-6069946ec596@eastlink.ca>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- 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> <alpine.LRH.2.00.1701141044230.4560@toltec.zanshin.com> <ac84bfaa-5034-8465-1ce9-6069946ec596@eastlink.ca>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author