How to Write a Script for Making Directories
On the Linux and Unix operating systems you can write a script that can create new directories using one of the shells (bash, sh, csh). A shell script uses common Unix commands to perform automated tasks. The following script requests the name of the directory from the user, creates the directory and returns the name and time the directory was created. It is written for the bash shell. Other shells use similar commands.
Instructions
-
-
1
Open a text editor such as vi or gedit.
-
2
Type the line "#!/bin/bash" to begin the script. This line tells the operating system which shell to use.
-
-
3
Type the next two lines to ask the user for the name of the directory and place that name in a variable called "directory."
echo "What is the name of the directory?"
read directory -
4
Type the line "mkdir $directory" to create a directory with the name specified by the user.
-
5
Type the following two lines to let the user know that the directory has been created and show the time it was created.
echo "Your directory has been created:"
ls -la | grep $directory
-
1