Reputation: 443
I am trying to create a folder tree using the mkdir command, which is supposed to have the following structure:
rootfs
├── Fol1
│ ├── Fol11
│ └── Fol12
└── Fol2
I sucessfully created this tree using
mkdir -p /rootfs/{Fol1/{Fol11,Fol12},Fol2}
However the folder rootfs is supposed to be variable, which is why I tried
ROOT=/rootfs
FOLDERTREE=/{Fol1/{Fol11,Fol12},Fol2}
mkdir -p "$ROOT$FILETREE"
Although echo "$ROOT$FILETREE"
yields exactly /rootfs/{Fol1/{Fol11,Fol12},Fol2}
I do get a wrong filetree
rootfs
└── {Fol1
└── {Fol11,Fol12},Fol2}
What am I doing wrong here ?
Upvotes: 4
Views: 133
Reputation: 785058
You can use BASH array to keep all the directory paths as:
dirs=( "${ROOT}"/{Fol1/{Fol11,Fol12},Fol2} )
Then create it as:
mkdir -p "${dirs[@]}"
Upvotes: 4
Reputation: 780869
Braces are not processed in the result of variable substitution. Use:
mkdir -p "$ROOT"/{Fol1/{Fol11,Fol12},Fol2}
Upvotes: 5