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

Re: Anonymous array indexing



In the last episode (Dec 12), Steve Talley said:
> Is there a compact version of the following:
> 
>     fred=(one two three)
>     export FRED=$fred[2]
>     unset fred
> 
> I am looking for something like
> 
>     export FRED=(one two three)[2]

Assuming "one two three" is actually stored in a shell variable (we'll
call it a):

export FRED=${${=a}[2]}

will work. = turns on SH_WORD_SPLIT, essentially turning the variable
into an array temporarily.


-- 
	Dan Nelson
	dnelson@xxxxxxxxxxxx



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