ZSH for loop array variable issue

arrays, for-loop, shell, unix, zsh

Solution

It's actually much simpler than that:

lw=('plugin1' 'plugin2' 'plugin3')

for i in $lw; do
  . ~/Library/Rogall/plugins/$i/lw.prg end
done

In summary:

- Assign to `foo`, not `$foo` (the shell would try to expand `$foo` and assign to whatever it expands to; typically not useful)

- Use the loop variable directly; it contains the array value rather than the index

Problem

I'm working in zsh, but I'm sure that bash instructions will also be helpful. I need to have a for loop that goes through the values stored in the array `lw` and then launches a shell script, based on the name value stored in the array. So far, this is what I've come up with: ``` $lw=('plugin1' 'plugin2' 'plugin3') for i in $lw; do . ~/Library/Rogall/plugins/$lw[$i]/lw.prg end; done ``` Running this gives me an error saying that it can't find `~/Library/Rogall/plugins//lw.prg`. It appears as if it's ignoring my variable all together. Any ideas where I've messed up?

Original source