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
  • 349,597
  • 67
  • 533
  • 578
Ramy
  • 20,541
  • 41
  • 103
  • 153

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
  • 349,597
  • 67
  • 533
  • 578