ZSH iterate through string array containing spaces
It has nothing to do with $IFS
. You are simply getting the syntax wrong.
This is how you would normally iterate over an array in zsh
:
% arr=( 'this is' 'a test' 'of the' 'emergency broadcast system' )
% for str in "$arr[@]"; do print -- $str; done
this is
a test
of the
emergency broadcast system
%
Alternatively, if you actually need to iterate over the array indices, then you would do it like this:
% for (( i = 1; i <= $#arr[@]; i++ )) do; print -- $arr[i]; done
Of course, if you just want to print the elements of the array as a vertical list, then you don't need to use a loop at all:
% print -l -- "$arr[@]"
this is
a test
of the
emergency broadcast system
%