markpatterson
Registered
Hi,
I was trying to write a bash script taking the argument start or stop. I read up at this tutorial
http://pegasus.rutgers.edu/~elflord/unix/bash-tute.html
and it appears there is an elsif, but it doesn't work for me. I have had to do separate if statements.
Here is (most of) the offending code:
Invoking it looks like this:
Pattersons-eMac:~ root# lamp.sh stop
/Users/mark/Dev/scripts/lamp.sh: line 20: syntax error near unexpected token `then'
/Users/mark/Dev/scripts/lamp.sh: line 20: `elsif [$1 = "stop" ] ; then'
If I remove the elsif line and uncomment the commented out lines, it works.
If this a bash versions thing?
Regards,
Mark
I was trying to write a bash script taking the argument start or stop. I read up at this tutorial
http://pegasus.rutgers.edu/~elflord/unix/bash-tute.html
and it appears there is an elsif, but it doesn't work for me. I have had to do separate if statements.
Here is (most of) the offending code:
Code:
#!/bin/bash
if [ $1 = "start" ] ; then
echo "starting MySQL"
/Library/StartupItems/MySQL/MySQL start
echo "starting Apache"
apachectl start
# fi
# if [ $1 = "stop" ] ; then
elsif [$1 = "stop" ] ; then
echo "shutting down MySQL"
/Library/StartupItems/MySQL/MySQL stop
echo "shutting down Apache"
apachectl stop
fi
Invoking it looks like this:
Pattersons-eMac:~ root# lamp.sh stop
/Users/mark/Dev/scripts/lamp.sh: line 20: syntax error near unexpected token `then'
/Users/mark/Dev/scripts/lamp.sh: line 20: `elsif [$1 = "stop" ] ; then'
If I remove the elsif line and uncomment the commented out lines, it works.
If this a bash versions thing?
Regards,
Mark