4

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 ?

2 Answers 2

5

Braces are not processed in the result of variable substitution. Use:

mkdir -p "$ROOT"/{Fol1/{Fol11,Fol12},Fol2}
Sign up to request clarification or add additional context in comments.

Comments

4

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[@]}"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.