我有一个脚本,其中包含一个SELECT语句,用于进入多个子SELECT语句,但是一旦进入子SELECT语句,我似乎无法找到将其返回到主脚本的方法。 如果可能的话,我希望它能重新列出选项。
#!/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