0

I made a shell script to automize my mac configuration. I have a loop which creates symlinks based on how many files are in this list e. g.:

files=".zshrc .gitconfig"

for file in ${files}; do
    echo "Creating symlink to $file in $homedir."
    ln -sf ${dir}/${file} ${homedir}/${file}
done

When I run my script in bash it works just fine. But if I run it in zsh it creates a symlink called ".zshrc .gitconfig". How can I iterate like in bash?

c69
  • 19,951
  • 7
  • 52
  • 82
dan-koller
  • 218
  • 1
  • 4
  • 10
  • Add `setopt shwordsplit` to the top of your `zsh` script. – 0stone0 Apr 14 '21 at 13:24
  • [This](https://stackoverflow.com/a/64632374/14234726) post answered my question. I needed to create an array to iterate through the list.. mb! – dan-koller Apr 14 '21 at 13:31
  • @dankoller112: Either do a `for file in ${(z)files}` (which would split the content of the variable on IFS, like in bash), or make `files` an array. The latter would be IMHO the cleaner solution, in both zsh and bash. – user1934428 Apr 15 '21 at 08:40

0 Answers0