我有一個腳本,它有一個Select語句去多個子選擇語句,但是一旦我似乎無法弄清楚如何讓它回到主腳本。還可能的話我想它重新列出你使用一個循環做到這一點的選項Bash Shell腳本:嵌套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