0

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}"

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.