WEEKS_TO_SAVE=4
mkdir -p weekly.{0..$WEEKS_TO_SAVE}
gives me a folder called weekly.{0..4}
Is there a secret to curly brace expansion while creating folders I'm missing?
WEEKS_TO_SAVE=4
mkdir -p weekly.{0..$WEEKS_TO_SAVE}
gives me a folder called weekly.{0..4}
Is there a secret to curly brace expansion while creating folders I'm missing?
Another way of doing it without eval and calling mkdir only once:
Brace expansion does not support it. You will have to do it using a loop.
.
Curly braces don't support variables in BASH, you can do this:
If you happen to have
zsh
installed on your box, your code as written will work with Z-shell if you use#!/bin/zsh
as your interpreter:Example
bash
doesbrace expansion
beforevariable expansion
, so you getweekly.{0..4}
.Because the result is predictable and safe(Don't trust user input), you can use
eval
in your case:note:
eval
is evileval
carefullyHere,
$((..))
is used to force the variable to be evaluated as an integer expression.