LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   syntax error near unexpected token (http://www.linuxquestions.org/questions/linux-newbie-8/syntax-error-near-unexpected-token-613143/)

Aigarzs 01-12-2008 03:04 PM

syntax error near unexpected token
 
I am new to Linux. Working with Slackware 12.0

I am trying to activate firewall with following code:


Code:

#!/bin/bash

set -x

start_firewall()
{
echo "Starting firewall..."
# flush & iptables
}

stop_firewall()
{
echo "Stopping firewall..."
# flush
}

case "$1" in
        start)
                echo "Will now start firewall."
                start_firewall()
                echo "Done."
        stop)
                echo "Will now stop firewall."
                stop_firewall()
                echo "Done."
        restart)
                echo "Will now restart firewall."
                stop_firewall()
                start_firewall()
                echo "Done."
        *)
                echo "Usage $0 {start|stop|restart}"
esac

Getting error message:
Line 19: syntax error near unexpected token 'echo'
Line 19: ' echo "Done."'

Line 19 is the line in case selection, after start), after start_firewall(), echo "Done."

I have tried to:
1) change 1st line to #!/bin/sh
2) rewrite executable from 0 with mc edit and VIM

Can anybody help me? Thanks in advance.

Uncle_Theodore 01-12-2008 03:12 PM

case "$1" in
start)
echo "Will now start firewall."
start_firewall()
echo "Done." ;;
stop)
echo "Will now stop firewall."
stop_firewall()
echo "Done." ;;
restart)
echo "Will now restart firewall."
stop_firewall()
start_firewall()
echo "Done.";;
*)
echo "Usage $0 {start|stop|restart}";;
esac

btmiller 01-12-2008 03:15 PM

Don't use parens () when calling functions ... also, you need to end the individual switch cases with a double semicolon (;;). I've pasted a correct version of your script which works for mw...

Code:

#!/bin/bash

set -x

function start_firewall()
{
echo "Starting firewall..."
# flush & iptables
}

function stop_firewall()
{
echo "Stopping firewall..."
# flush
}

case "$1" in
        start)
                echo "Will now start firewall."
                start_firewall
                echo "Done."
                ;;
        stop)
                echo "Will now stop firewall."
                stop_firewall
                echo "Done."
                ;;
        restart)
                echo "Will now restart firewall."
                stop_firewall
                start_firewall
                echo "Done."
                ;;
        *)
                echo "Usage $0 {start|stop|restart}"
                ;;
esac


Aigarzs 01-12-2008 03:39 PM

Now it works. Thank You!


All times are GMT -5. The time now is 07:33 PM.