Brace expansion with a Bash variable - {0..$foo}
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 integer expression.
Curly braces don't support variables in BASH, you can do this:
for (( c=0; c<=WEEKS_TO_SAVE; c++ )) do mkdir -p weekly.${c} done
Another way of doing it without eval and calling mkdir only once:
WEEKS_TO_SAVE=4mkdir -p $(seq -f "weekly.%.0f" 0 $WEEKS_TO_SAVE)