0

I'm trying to make a bash script that would make a series of directories and requesting a parameter of how many directories should be created.

$> ./createDir.sh 5

$> ls

ex_01
ex_02
ex_03
ex_04
ex_05

I tried using mkdir ex_{01..$1} but it does not seem correct. How could I make this work (without using any loop)?

dr_
  • 29,602
RayedB
  • 3

1 Answers1

1

You will need eval for this.

#!/bin/bash

start=1
stop=$1

mkdir $(eval echo ex_{$start..$stop})

But I agree with don_crissti, why not simply use a loop?

Before:

ls -p | grep 'ex_'
<empty>

After I run the script:

./makeDirs.sh 3
ls -p | grep 'ex_'
ex_1/
ex_2/
ex_3/

Further reading: