You are using exit as a variable but it is a reserved word in bash. Change that, I used EXIT. You have the Backup and Restore functions inside the main_menu function, I would suggest putting them outside that function. Change
read choice to
read -n1 choice and the user doesn't have to press <Enter>.
Beside that all you really need is to let the user input a directory and then make the tarball.
I'll show you making the tarball and let you figure out the restore part.
Code:
#!/bin/bash
function backup () {
clear
echo "Which directory do you want to Backup?"
echo "***********"
read BDIR
if [ ! -d "$BDIR" ];then
echo "No such directory..."
return
fi
# Uncomment following line to make script work
# tar cjvf $(basename $BDIR).tar.bz2 $BDIR
echo "tar cjvf $(basename $BDIR).tar.bz2 $BDIR"
}
#*************************************
function restore () {
clear
echo "This is the Restore Application "
echo "***********"
#[Restore SCRIPT HERE]
}
function display_main_menu () {
clear
echo "Welcome to the backup program"
echo "***********"
echo "Menu"
echo "***********"
# List menu options
echo "Please choose from the following options: "
echo "A. Backup a directory"
echo "B. Restore a directory"
echo "C. Quit"
echo
EXIT="false"
while [ "$EXIT" = "false" ]
do
echo "***********"
echo -n "What is your choice? "
read -n1 choice
# See what the user has chosen to do
case "$choice" in
A|a )
backup
EXIT="true"
;;
B|b )
restore
EXIT="true"
;;
C|c )
exit
EXIT="true"
;;
* )
echo "Please enter valid choice"
;;
esac
done
}
display_main_menu