Say you have a zsh array like:
a=("x y" "v w")
I want to take the first word of every element, say:
b=()
for e in $a; {
b=($b $e[(w)0])
}
So now I have what I need in b:
$ print ${(qq)b}
'x' 'v'
Is there a way to do this in a single expansion expression? (i.e. not needing a for loop for processing each array element and accumulating the result in a new array).
It could be possible to take the word by removing from the first occurrence of a white space to the end in each element of the array like this:
It coulde be noted that the
%%
expression (and some others) could be used for array elements: