Skip to main content

Command Palette

Search for a command to run...

Advanced Linux Shell Scripting

Published
1 min read
S

DevOps Engineer

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

More from this blog

Untitled Publication

112 posts