Advanced Linux Shell Scripting

Sai Deva HarshaSai Deva Harsha
1 min read

Day-5 Task:

To write a shell script that will create directories up to N number.

  • #!/bin/bash

    if [ "$#" -ne 3 ]; then

    echo "Please provide directory name, start number, and end number as arguments."

    exit 1

    fi

    dir_name=$1

    start_num=$2

    end_num=$3

    for (( i=start_num; i<=end_num; i++ )); do

    dir="${dir_name}${i}"

    mkdir "$dir"

    done

To execute the task, we will write the command - ./createDirectories.sh dir 1 5

0
Subscribe to my newsletter

Read articles from Sai Deva Harsha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sai Deva Harsha
Sai Deva Harsha

DevOps Engineer