How To Create Multiple Directories Using A Shell Script?
Hi,
I am looking for a way of creating multiple directories using the mkdir -p command in a shell script.
I'm working with an Ubuntu machine and try to do something like that:
#!/bin/sh
# Create required directories to support pipelines (BWAse, BWApe, and others to come...)
echo ***Creating Directory Structure***
mkdir -p "temp/{temp1,temp2, temp3}"
mkdir -p temp/down/{struc1,struc2,struc3,struc4}
I would like to have each of the directories in the {} as sub-directories of the directory before.
The problem is that I get only one directory with the complete name inclusive the {}. It looks like that:
ll -R temp
temp:
total 16
drwxr-xr-x 4 USER 4096 2011-10-11 09:53 ./
drwxr-xr-x 31 USER 4096 2011-10-11 09:53 ../
drwxr-xr-x 3 USER 4096 2011-10-11 09:53 down/
drwxr-xr-x 2 USER 4096 2011-10-11 09:53 {temp1,temp2, temp3}/
temp/down:
total 12
drwxr-xr-x 3 USER 4096 2011-10-11 09:53 ./
drwxr-xr-x 4 USER 4096 2011-10-11 09:53 ../
drwxr-xr-x 2 USER 4096 2011-10-11 09:53 {struc1,struc2,struc3,struc4}/
temp/down/{struc1,struc2,struc3,struc4}:
total 8
drwxr-xr-x 2 USER 4096 2011-10-11 09:53 ./
drwxr-xr-x 3 USER 4096 2011-10-11 09:53 ../
temp/{temp1,temp2, temp3}:
total 8
drwxr-xr-x 2 USER 4096 2011-10-11 09:53 ./
drwxr-xr-x 4 USER 4096 2011-10-11 09:53 ../
What am doing wrong? IS there a way of automating this procedure?
Thanks
Assa
• 11,288 views
•
link
2 answers
for dir in struc1 struc2 struc3 struc4 do mkdir -p temp/${dir} done
• 1 views
•
link
BASENAME=Temp[?] STARTDIR=1[?] ENDDIR=102[?]
mkdir $BASENAME$(seq -w -s " $BASENAME" $STARTDIR $ENDDIR)[?] [?]
try this! hth!
• 0 views
•
link
Log in to answer this question.
This is off-topic it is a basic shell scripting question that has nothing to do with bioinformatics. Ask this type of questions on stackoverflow. closing it now.
Of course, shell scripting has a lot to do with bioinformatics (for some people), but you should mention some context so people might understand why in a bioinformatics setting it would be useful to create multiple directories with a shell script. This way, even though your question gets an up vote and two answers, it won't be closed as "off topic", despite it's pedagogical value in showing the curious some nifty scripting tips.
I just noticed that you actually did mention a context: BWA pipelines...and your question was still closed as off topic. Incredible.