I need help writing a shell script for this scenario: You want to create individ
ID: 3708513 • Letter: I
Question
I need help writing a shell script for this scenario: You want to create individual work directories for all employees. Because the task of creating directories individually is time consuming, you decide to write a shell script to automate the process:
* Following are the details for writing the bash script: Name of the script: userdir
Prompt text to remind the users to enter the number of directories required: Specify the number of directories to be created
Name of the variable to get the total number of directories: Numberofdir
Name of the variable to be used in the for loop to store the number of directories: d
I have started this script and cannot figure out where my problem is can someone please help me
Explanation / Answer
There is nothing mentioned about the name of directories to be created. The below shell script asks for number fo directories and creates directories with dir0, dir1, ..., dirN-1, dirN were N is the input given by user. Also it creates in the current directory where you run the code.
Script for creating directories.
userdir.sh
#!/bin/bash
# Prompt text for user
echo "Specify the number of directories to be created"
read Numberofdir
d=0
while [ $d -lt $Numberofdir ];
do
echo "Creating directory dir$d"
mkdir dir$d
d=$(($d+1))
done
Sample output (Change mode of script to executable before running the script)
./userdir.sh
Specify the number of directories to be created
4
Creating directory dir0
Creating directory dir1
Creating directory dir2
Creating directory dir3