0

Based on this answer: https://stackoverflow.com/a/4141042/226473

I came up with this script:

ALT02884% for i in {0..4}
do
  printf "Set for $1" > "$i_directories"
done

But it results in the following:

zsh: no such file or directory:
zsh: no such file or directory:
zsh: no such file or directory:
zsh: no such file or directory:
zsh: no such file or directory:
John Kugelman
  • 330,190
  • 66
  • 504
  • 555
Ramy
  • 19,312
  • 38
  • 98
  • 146

1 Answers1

1

The shell thinks the underscore is part of the variable name. Use curly braces to tell it to look for a variable named i rather than i_directories.

for i in {0..4}
do
  printf "Set for $1" > "${i}_directories"
done
John Kugelman
  • 330,190
  • 66
  • 504
  • 555