paulsp
October 16th, 2010, 03:58 AM
I just started looking around in bash and options to tweak it. Absolutely interesting! But I am stuck at the following. The idea is that you type "apache" and get the option list. This works fine. But I also want - alternatively - to be able to type "apache Start" and right away run the command listed under the Start option. Is this possible?
function apache
{
OPTIONS="Start Stop Restart Status"
select opt in $OPTIONS; do
if [ "$opt" = "Start" ]; then
sudo /etc/init.d/apache2 start
return
elif [ "$opt" = "Stop" ]; then
sudo /etc/init.d/apache2 stop
return
elif [ "$opt" = "Restart" ]; then
sudo /etc/init.d/apache2 restart
return
elif [ "$opt" = "Status" ]; then
sudo /etc/init.d/apache2 status
return
else
echo "Sorry, not valid"
fi
done
}
function apache
{
OPTIONS="Start Stop Restart Status"
select opt in $OPTIONS; do
if [ "$opt" = "Start" ]; then
sudo /etc/init.d/apache2 start
return
elif [ "$opt" = "Stop" ]; then
sudo /etc/init.d/apache2 stop
return
elif [ "$opt" = "Restart" ]; then
sudo /etc/init.d/apache2 restart
return
elif [ "$opt" = "Status" ]; then
sudo /etc/init.d/apache2 status
return
else
echo "Sorry, not valid"
fi
done
}