James James - 2 months ago 16
Linux Question

Creating a full directory tree at once

I'm like a create a complex directory structure in a bash script and was under the impression the the following would work:

mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}


Which would create:

tmpdir
________|______
| | |
branches tags trunk
|
sources
____|_____
| |
includes docs


However when I run my script I end up with:

tmpdir
|
trunk


Is there a quick and easy way to do this or am I going to have to resort to

mkdir -p tmpdir/trunk/sources/includes
mkdir -p tmpdir/trunk/sources/docs
mkdir -p tmpdir/branches
mkdir -p tmpdir/tags

Answer

Change shebang to

#!/bin/bash

to run the script with bash as it supports brace expansion.

The problem is that you are using shell that does not support it. Your /bin/sh does not point to /bin/bash but to something like /bin/dash.

https://wiki.ubuntu.com/DashAsBinSh#A.7B