I would like to create a complex directory structure in a bash script and was under the impression that 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
Creation of an entire directory tree can be accomplished with the mkdir command, which (as its name suggests) is used to make directories. The -p option tells mkdir to create not only a subdirectory but also any of its parent directories that do not already exist.
You can create directories one by one with mkdir, but this can be time-consuming. To avoid that, you can run a single mkdir command to create multiple directories at once. To do so, use the curly brackets {} with mkdir and state the directory names, separated by a comma.
If you want to create a directory containing several subdirectories, or a directory tree, using the command line in Linux, generally you have to use the mkdir command several times.
Just create a loop that generates a number and saves it to a file until it's created 100. Then read those 100 files into an array. Sort the array to have the numbers in order. Convert the array to a string, and save it to a new text file.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With