I am trying to write a ZSH script which will iterate through a series of strings that contain spaces.
First, I'll set -A the array:
set -A a "this is" "a test" "of the" "emergency broadcast system"
From here, I'll try to iterate through it using a basic for loop, making sure to wrap the array in quotes to handle the spaces:
for i in "$a"; do echo "${a[$i]}"
However, this throws the following error:
zsh: bad math expression: operator expected at `is a test ...'
I've been playing around with this for a bit, even trying setting the delimiter to "\n" since I think the issue is the array is using spaces as delimiters, but even doing:
a=(IFS=$'\n';"this is" "a test" "of the" "emergency broadcast system")
followed by:
for i in "$a"; do echo "${a[$i]}"; done
yields the same ZSH error.