You are not logged in.

#1 2008-04-26 16:03:22

Benedict_White
Member
From: Sussex, UK
Registered: 2004-05-27
Posts: 333
Website

bash script question, how do I create multiple directories on one line

I am making a package for amavisd-new (yes I am aware that there is one in community but I can't say I like the way it is done).

I have an install script from which I want to create multiple directories if they do not exist.

So I want to create a directory /var/spool/amavis with subdirectories of var tmp virusmails spammassassin .

I can't seem to be able to find a way to do this on one line.


Kind regards

Benedict White

Offline

#2 2008-04-26 16:09:29

chimeric
Member
From: Munich, Germany
Registered: 2007-10-07
Posts: 254
Website

Re: bash script question, how do I create multiple directories on one line

Hi,

the following should work:

% mkdir -p /var/spool/avamis/{virusmails,spammassassin}

or if you need to set certain permissions (see install --help for more information):

% install -d /var/spool/avamis/virusmails /var/spool/avamis/spammassassin

Last edited by chimeric (2008-04-26 16:13:18)

Offline

#3 2008-04-26 16:10:40

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: bash script question, how do I create multiple directories on one line

mkdir supports multiple directories? If you are using bash you might use this better readable syntax: mkdir -p /var/spool/amavis/{var,tmp,virusmails,spamassassin}

Offline

#4 2008-04-27 00:32:11

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: bash script question, how do I create multiple directories on one line

If you're not using bash you can always use a for loop, does that count as one line?

for dir in var tmp virusmails spamassassin; do mkdir "/var/spool/amavis/$dir"; done

Offline

#5 2008-04-27 08:41:02

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: bash script question, how do I create multiple directories on one line

Why would you use a loop when, like I posted, mkdir supportes multiple directories?

mkdir -p  /var/spool/avamis/var /var/spool/avamis/tmp /var/spool/avamis/virusmails /var/spool/avamis/spammassassin

Offline

#6 2008-04-27 20:29:24

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: bash script question, how do I create multiple directories on one line

Hehe because it's less typing! big_smile

Offline

#7 2008-04-27 22:05:18

pelle.k
Member
From: Åre, Sweden (EU)
Registered: 2006-04-30
Posts: 667

Re: bash script question, how do I create multiple directories on one line

peets wrote:

Hehe because it's less typing! big_smile

Good one! smile
Also, it's by far the more dynamic method.


"Your beliefs can be like fences that surround you.
You must first see them or you will not even realize that you are not free, simply because you will not see beyond the fences.
They will represent the boundaries of your experience."

SETH / Jane Roberts

Offline

#8 2008-04-27 22:41:40

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: bash script question, how do I create multiple directories on one line

pelle.k wrote:
peets wrote:

Hehe because it's less typing! big_smile

Good one! smile
Also, it's by far the more dynamic method.

If you want to get pedantic, it's also far less efficient in terms of execution time: each iteration of the loop forks a new process, whereas using a single mkdir command forks only once.  The "best" way is the curly-braces method demonstrated above by chimeric.

Offline

Board footer

Powered by FluxBB