I thought the following would group the output of
my_command in an array of lines:
$array_of_lines would refer to the first line in the output of
$array_of_lines to the second, and so forth.
However, the command above doesn't seem to work well. It seems to also split the output of
my_command around the character
n, as I have checked with
print -l $array_of_lines, which I believe prints elements of an array line by line. I have also checked this with:
echo $array_of_lines echo $array_of_lines ...
In a second attempt, I thought adding
eval could help:
IFS='\n' array_of_lines=$(eval my_command);
but I got the exact same result as without it.
Finally, following the answer on List elements with spaces in zsh, I have also tried using parameter expansion flags instead of
IFS to tell zsh how to split the input and collect the elements into an array, i.e.:
But I still got the same result (splitting happening on
With this, I have the following questions:
Q1. What are "the proper" ways of collecting the output of a command in an array of lines?
Q2. How can I specify
IFS to split on newlines only?
Q3. If I use parameter expansion flags as in my third attempt above (i.e. using
@f) to specify the splitting, does zsh ignore the value of
IFS? Why didn't it work above?