Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: help with dereferencing variables
- X-seq: zsh-users 7059
- From: "S. Cowles" <scowles@xxxxxxxxxxxxx>
- To: zsh users <zsh-users@xxxxxxxxxx>
- Subject: Re: help with dereferencing variables
- Date: Sat, 14 Feb 2004 20:12:32 -0800
- In-reply-to: <1040214212400.ZM15293@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: personal
- References: <200402140959.24015.scowles@xxxxxxxxxxxxx> <1040214212400.ZM15293@xxxxxxxxxxxxxxxxxxxxxxx>
- Reply-to: scowles@xxxxxxxxxxxxx
Many thanks; that was the info I was missing. One small aesthetics preference
following up on your suggestion and I'm away (does not preserve newlines in
the array element assignments):
eval ${key}\=\( ${(P)val} \)
cheers.
On Saturday 14 February 2004 13:24, Bart Schaefer wrote:
> On Feb 14, 9:59am, S. Cowles wrote:
> }
> } In the following code, method 1 gives the expected results. Method
> } 2, however, breaks with the error: unknown file attribute. Is the
> } eval in Method 1 required, or is there a correct syntax to make the
> } dereference occur in Method 2 without an eval?
>
> The short answers are "not precisely" and "no".
>
> } # method 1:
> } b=$(echo "${key}=( ${(@)${(P)val}} )")
> } eval $b
>
> You don't need the $(echo) and the assignment to $b here. It should be
> enough to do
>
> eval ${key}'=( ${(P)val} )'
>
> (note placement of single quotes).
>
> } # method 2:
> } ${key}=( ${(@)${(P)${val}}} )
>
> This syntax is not an assignment, because the stuff to the left of the
> equals sign is not an identifier name. (This used to work in older
> versions of zsh because the variable was expanded before zsh looked
> for assignment syntax, but that was incompatible with other shells.)
>
> Even if this were an assignment, The ${(@)...} is extraneous when the
> whole thing is not in double quotes. And you don't need ${(P)${val}},
> just ${(P)val} is enough.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author