Writing a bash shell script called “ test.sh ” that will creates directory using MENU DRIVEN, considering the following:

  • Making a new directory using (mkdir.sh)
  • Read In directory name (may enter a path)
  • Check If it exists.
  • If it does, warn user.
  • Otherwise create it.

# !/bin/bash
# MENU DRIVEN BASH SCRIPT CREATED BY Nathan Joseph (http://NJ180degree.net)
# CREATED ON DECEMBER 26th 2009
# ISSUED UNDER THE GNU GPL

echo "Hello $USER, Welcome to NATHAN CONTROL MENU"
echo "The Date & Time is:"
date

function MAKEDIR {
	echo -e "Please enter a directory name"
	read DIRK
	if [ ! -d $DIRK ]
	then
		mkdir $DIRK #Notice: You can restrict the directory path to '$USER/home'
		echo -e "Directory $DIRK created"
		echo -e "Directory $DIRK created"
	else
		echo -e "$DIRK directory already exists!"
		echo -e "1.Faild to create $DIRK directory, Directory already exists"
fi
}

echo -e "Please choose from the following options by entering 0 or 1"
echo -e "1- Create New Directory!"
echo -e "0. Exit"

read option
while [ "$option" != "0" ]
	do
		case $option in
			1) MAKEDIR ;;
			*) echo -e "Invaild choice, please choose from 0 or 1 only" ;;
			0) echo -e "Thanks for using my script.. you can change or modify it to suit your purposes"
			echo -e "0.Exit the program"
			exit 0

			 ;;
		esac
		echo -e "Please press return to go back to main menu"
		read RETURN
		echo -e "Please choose from the following options by entering 0 or 1"
		echo -e "1- Create New Directory!"
		echo -e "0. Exit"
			read option
	done
echo -e "Thanks for using my script.. you can change or modify it to suit your purposes"
exit

Enjoy.. :)

# !/bin/bash
# MENU DRIVEN BASH SCRIPT CREATED BY Nathan Joseph (http://NJ180degree.net)
# CREATED ON DECEMBER 26th 2009
# ISSUED UNDER THE GNU GPL (GNU GPL)
# Writing a bash shell script called “test.sh” that will creates directoriy using MENU DRIVEN, considering the follwoing:
echo “Hello $USER, Welcome to NATHAN CONTROL MENU”
echo “The Date & Time is:”
date

function MAKEDIR {
echo -e “Please enter a directory name”
read DIRK
if [ ! -d $DIRK ]
then
mkdir $DIRK #Notice: You can restrict the directory path to ‘$USER/home’
echo -e “Directory $DIRK created”
echo -e “Directory $DIRK created”
else
echo -e “$DIRK directory already exists!”
echo -e “1.Faild to create $DIRK directory, Directory already exists”
fi
}

echo -e “Please choose from the following options by entering 0 or 1″
echo -e “1- Create New Directory!”
echo -e “0. Exit”

read option
while [ "$option" != "0" ]
do
case $option in
1) MAKEDIR ;;
*) echo -e “Invaild choice, please choose from 0 or 1 only” ;;
0) echo -e “Thanks for using my script.. you can donate all your money to me:)”
echo -e “0.Exit the program”
exit 0

;;
esac
echo -e “Please press return to go back to main menu”
read RETURN
echo -e “Please choose from the following options by entering 0 or 1″
echo -e “1- Create New Directory!”
echo -e “0. Exit”
read option
done
echo -e “Thanks for using my script.. you can donate all your money to me :)
exit


  • Share/Bookmark