Day 5 - Shell Scripting using loops

Riya VyasRiya Vyas
1 min read

Task 1 -

Write a bash script createDirectories.sh that when the script is executed with three given arguments (one is directory name and second is start number of directories and third is the end number of directories ) it creates specified number of directories with a dynamic directory name.

Example 1: When the script is executed as

./createDirectories.sh day 1 90

then it creates 90 directories as day1 day2 day3 .... day90

Example 2: When the script is executed as

./createDirectories.sh Movie 20 50 then it creates 50 directories as Movie20 Movie21 Movie23 ...Movie50

#!/bin/bash

#################################
# Author : Riya Vyas
#
# Date : 26/08/2023
#
# This is a script that takes the base name for directories and range to make a list of directories using a for loop
##################################


echo "Enter the Directory base name: "
read base
echo "Enter the starting number :"
read start_num
echo "Enter the ending number: "
read end_num

#for i in {$start..$end}
for (( i = start_num; i <= end_num ; i++ ));
do
        mkdir $base$i
done

Output -

Sample run 1 -

Sample run 2 -

0
Subscribe to my newsletter

Read articles from Riya Vyas directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Riya Vyas
Riya Vyas