Bash Shell Script: Nested Select Statements
Posted
by CCG121
on Stack Overflow
See other posts from Stack Overflow
or by CCG121
Published on 2010-04-08T00:29:27Z
Indexed on
2010/04/08
0:33 UTC
Read the original article
Hit count: 418
I have A Script that has a Select statement to go to multiple sub select statements however once there I can not seem to figure out how to get it to go back to the main script. also if possible i would like it to re-list the options
#!/bin/bash
PS3='Option = '
MAINOPTIONS="Apache Postfix Dovecot All Quit"
APACHEOPTIONS="Restart Start Stop Status"
POSTFIXOPTIONS="Restart Start Stop Status"
DOVECOTOPTIONS="Restart Start Stop Status"
select opt in $MAINOPTIONS; do
if [ "$opt" = "Quit" ]; then
echo Now Exiting
exit
elif [ "$opt" = "Apache" ]; then
select opt in $APACHEOPTIONS; do
if [ "$opt" = "Restart" ]; then
sudo /etc/init.d/apache2 restart
elif [ "$opt" = "Start" ]; then
sudo /etc/init.d/apache2 start
elif [ "$opt" = "Stop" ]; then
sudo /etc/init.d/apache2 stop
elif [ "$opt" = "Status" ]; then
sudo /etc/init.d/apache2 status
fi
done
elif [ "$opt" = "Postfix" ]; then
select opt in $POSTFIXOPTIONS; do
if [ "$opt" = "Restart" ]; then
sudo /etc/init.d/postfix restart
elif [ "$opt" = "Start" ]; then
sudo /etc/init.d/postfix start
elif [ "$opt" = "Stop" ]; then
sudo /etc/init.d/postfix stop
elif [ "$opt" = "Status" ]; then
sudo /etc/init.d/postfix status
fi
done
elif [ "$opt" = "Dovecot" ]; then
select opt in $DOVECOTOPTIONS; do
if [ "$opt" = "Restart" ]; then
sudo /etc/init.d/dovecot restart
elif [ "$opt" = "Start" ]; then
sudo /etc/init.d/dovecot start
elif [ "$opt" = "Stop" ]; then
sudo /etc/init.d/dovecot stop
elif [ "$opt" = "Status" ]; then
sudo /etc/init.d/dovecot status
fi
done
elif [ "$opt" = "All" ]; then
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/postfix restart
sudo /etc/init.d/dovecot restart
fi
done
© Stack Overflow or respective owner