Menu driven script.

I'm a beginner at scripting and have been putting this script together over the past week. It's no where as polish as it could be. Any tips/suggestions on improving this script would be appreciate it. Every week, my team develops WAR files in tomcat on our test environment and moves them to our production environment. The script is to suppose automated the process. I put comments in each section to explain what it�s supposed to do. The only thing I can�t figure out is how to keep the script continue running until the #5 is enter to exit the script. I would like to run each portion of the script and have it go back to the menu so I can input the next number. Right now, after I run numbers 1-4 after the command is run, I need to execute the script again.

#!/bin/sh


### To Start and Stop Tomcat

f1 () {

while :
do
echo "Do you want to startup or shutdown Tomcat?"
echo "* [start] Startup Tomcat *"
echo "* [stop] Shutdown Tomcat *"
echo "Enter your choice : "
read input
case $input in

start) su - tomcat /usr/local/apache-tomcat-7.0.8/bin/startup.sh
    break;;
stop) su - tomcat /usr/local/apache-tomcat-7.0.8/bin/shutdown.sh
    break;;
*) echo "Invalid Choice";

echo "Press Enter to continue: " ; read ;;
esac
done
}

f2 () {

### renames the hostname and doain in the tomcat properties files our test machines to our prodution machine names

HOSTNAME=`hostname`

sed -i "s/prime.test.domain/$HOSTNAME/g" *.properties*
sed -i "s/prime/$HOSTNAME/g" *.properties*
sed -i "s/jazz.test.domain/$HOSTNAME/g" *.properties*
sed -i "s/jazz/$HOSTNAME/g" *.properties*
}


f3 () {

### deploys the WAR files to tomcat.  All WAR and properties files are copied to the deploy directory from our test network.

CONFIG=/opt/test/config
DEPLOY=/opt/test/deploy
TOMCAT=/usr/local/apache-tomcat-7.0.

\rm -R $TOMCAT/webapps/*.war $TOMCAT/webapps/Leo*
\rm -R $TOMCAT/work/Catalina/localhost/Leo*

cp $DEPLOY/*.war $TOMCAT/webapps
cp $DEPLOY/*.properties $CONFIG

chown -R user:group $TOMCAT $CONFIG
}

f4 () {

###Create a mysql database

MYSQLADM="root"
TESTADM="testuser"
TESTPW="password"

echo "Enter database name"
read dbname
echo "Enter MYSQLPW Password "
read -s MYSQLPW

mysql -u "$MYSQLADM -p"MYSQLPW" mysql -e "create database $dbname; grat all privileges on $dbname.* to $TESTADM@'localhost;"

echo "Database $dbname has been created"

}


f5 () {

exit
}

echo "Enter Choice:

1) Startup/shutdown Tomcat:
2) Replace Test names with production names:
3) Delete and Deploy new WAR Files:
4) Create new mysql database:
5) Exit:"

read choice

set -- $choice

for i in $@
do
#    echo "run function $i"
    f${i}
done
f5 () {
exit
}

exit will stop and exit from the script.

So what do you want to do after choice 5?

If you want to keep the script running, you can replace exist to continue.

Thank you for the followup.

What I want the script to do is keeping repeating it's self until the exit is called in f5. For example, when the user selects 1 to start/stop tomcat. After that command is executed, I want the script to go back to the menu to allow the user to input another option. Right now, after 1 is select, I need to rerun the script to get the menu back.

Thanks

put for loop in while endless loop.

while true
do
  echo "Enter Choice:

  1) Startup/shutdown Tomcat:
  2) Replace Test names with production names:
  3) Delete and Deploy new WAR Files:
  4) Create new mysql database:
  5) Exit:"

  read choice

  set -- $choice

  for i in $@
  do
  #    echo "run function $i"
      f${i}
  done

done

That did the trick. Thank you for your assistance.