I did in Zsh:
array={geometry, analysis, topology, graph theory, calculus}
echo $array
and then I wanted to add word "math:" to each element like" math:calculus":
while (( i++ < 10)); { echo math:$array[i] }
But it does not work? Why?
I did in Zsh:
array={geometry, analysis, topology, graph theory, calculus}
echo $array
and then I wanted to add word "math:" to each element like" math:calculus":
while (( i++ < 10)); { echo math:$array[i] }
But it does not work? Why?
Works fine for me in zsh with the assignment changed from:
array={geometry, analysis, topology, graph theory, calculus}
to
array=(geometry, analysis, topology, graph theory, calculus)
But zsh has tons of options that change its behavior. Maybe the output 'setopt' might help.
Just do:
array=(geometry analysis topology "graph theory" calculus)
print -l math:${^array}
or check RC_EXPAND_PARAM
for the ${^var}
form.
Welp, I'm going to go out on a limb here (because I don't accept that the supporting code is correct) and say that "echo math:$array[i]" is missing a dollar sign and should be "echo math:$array[$i]"
Iterating through an array works better with for
because you won't over run the end like your code will (unless you set your limit to the size of the array with ${#array[*]}).
Also, I assume you don't want the commas to be included as part of the strings and you should use parentheses instead of curly braces for your array.
array=(geometry analysis topology "graph theory" calculus)
for i in $array; do echo math:$i; done