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

Treating $(...) as an array



You can force $(...) to be interpreted as an array when assigning it to a
variable:

zsh% x=($(print -l "One two" "Three four" "Five six"))
zsh% echo $#x
6

You can force a string variable to be interpreted as an array:

zsh% x="$(print -l "One two" "Three four" "Five six")"
zsh% echo ${x[2]} ${x[(w)2} ${x[(f)2]}
n two Three four

You can use $(...) as a string substitution inside ${...}:

zsh% echo ${(L)$(print -l "One two" "Three four" "Five six")}
one two three four five six

You can use modifiers on $(...) when it appears as a string substitution:

zsh% echo ${$(print -l "One two" "Three four" "Five six"):l}
one two three four five six

So, WHY can't you force $(...) to be interpreted directly as an array
when it appears as a string substitution?

zsh% echo ${$(print -l "One two" "Three four" "Five six")[(f)2]}
zsh: closing brace expected

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"




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