Reputation: 25
I am trying to write a bash script and part of the script is to check for multiple directories and if the directories don't exist then make them. Can someone help me on this?
The directories look like this
EX: /mk1 /mk2 /mk3 /mk4 ... /mk22
I have the make the directory part.
"else mkdir {/mk1../mk22}"
Upvotes: 0
Views: 201
Reputation: 530823
bash
doesn't know how to increment complex alphanumeric strings. You have to "factor out" the alphabetic part so that you can iterate over the solely numeric part.
mkdir -p /mk{1..22}
The -p
tell mkdir
to make the directory if necessary, so you don't have to check if they exist first.
Upvotes: 1