Using a variable in brace expansion range fed to a for loop
You should use a C-style for loop to accomplish this: for ((i=1; i<=$1; i++)); do echo $i done This avoids external commands and nasty eval statements.
You should use a C-style for loop to accomplish this: for ((i=1; i<=$1; i++)); do echo $i done This avoids external commands and nasty eval statements.
bash does brace expansion before variable expansion, so you get weekly.{0..4}. Because the result is predictable and safe(Don’t trust user input), you can use eval in your case: $ WEEKS_TO_SAVE=4 $ eval “mkdir -p weekly.{0..$((WEEKS_TO_SAVE))}” note: eval is evil use eval carefully Here, $((..)) is used to force the variable to be evaluated as an … Read more