Reputation: 1
I am trying out a test script but sadly it's no working.. I am trying to create an x amount of directories based on the users input. I also would like to create a follow number for example if the user inputs the number 5, then 5 individual directories would be created like so; nameofdirectory1, nameofdirectory2 nameofdirectory3 etc.
This is what I have right now;
#!/bin/bash
#Testing1
echo "How many directories do you want"
read INPUT
mkdir -p nameofdirectory{1..$INPUT};
When I execute the script it runs fine but it only makes 1 directory. For example if my input would be 5 then the directory that would be created is: "nameofdirectory1..5" instead of the 5 individual directories I am trying to create. How do I fix this?
Upvotes: 0
Views: 45
Reputation: 1
> Answer by @alaniwi
#!/bin/bash
#Testing
echo "How many directories do you want"
read INPUT
mkdir -p $(seq -f "nameofdirectory%g" 1 $INPUT)
Upvotes: 0
Reputation: 578
The input is being treated as a string, so the creation of a directory with the name nameofdirectory{1..5}
is expected.
Try this:
#!/bin/bash
#Testing1
echo "How many directories do you want"
read INPUT
for i in $(seq 1 $INPUT);
do
mkdir -p nameofdirectory$i;
done;
Upvotes: 1