Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: proxy name for array




On 2024-01-09 18:29, Bart Schaefer wrote:
On Tue, Jan 9, 2024 at 4:54 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
proxy_assign="${proxy}[2]"
: ${(P)proxy_assign::=TWO}
Actually I just thought of a much more straightforward way to do this.

   set -A "${proxy}[2]" TWO

I had always thought "set -A" would complain about needing an
identifier, there, but it doesn't, and the semantics of assigning an
array to an array element make this work.

Sheesh, that was easy.  Only thing is having to chop it up into an array again:

Run:

LIST=( one two three four five )
echo $LIST
proxy="LIST"
set -A "${proxy}" "onezies toony threeatlast forlorn fivealive"
echo $LIST
LIST=( ${=LIST} )
echo $LIST[2,3]

... gives:

one two three four five
onezies toony threeatlast forlorn fivealive
toony threeatlast

... I wonder if it's smart enough to accept array output directly?  Tried a few things with no luck.

Tx.  Bart, would you please give me someplace to read up on " ::= " also on the leading colon -- for the previous method.  I have no idea what that does but it can't be omitted.




Messages sorted by: Reverse Date, Date, Thread, Author