I would like to instantiate a zsh array from a subshell
myarray=($(somecommand)
and I check if I received what I wanted with
for element in $myarray ; do echo "===" ; echo $element ; echo "---" ; done
By default I see that whitespaces (spaces and line breaks) are used to separate elements.
I also found that I can use ${(s:-:)"$(somecommand)"}
to separate by -
, in which case spaces and line breaks do not break elements (i.e. array elements can contain line breaks).
So far I fail to split at line breaks only. I.e. if somecommand
returns
Alice
Bob
Arthur C Clarke
Neo
Thomas Anderson
I want my above for
loop to print:
===
Alice
---
===
Bob
---
===
Arthur C Clarke
---
===
Neo
---
===
Thomas Anderson
---
How do I achieve that? (And possibly pointers where to look that up in the manual.)