user2821177
user2821177

Reputation: 25

Bash Script Check for Multiple Directories

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

Answers (1)

chepner
chepner

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

Related Questions