LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 01-12-2008, 04:04 PM   #1
Aigarzs
LQ Newbie
 
Registered: Jan 2008
Distribution: Slackware
Posts: 19

Rep: Reputation: 0
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.
 
Old 01-12-2008, 04:12 PM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
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

Last edited by Uncle_Theodore; 01-12-2008 at 04:13 PM.
 
Old 01-12-2008, 04:15 PM   #3
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,160

Rep: Reputation: 329Reputation: 329Reputation: 329Reputation: 329
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
 
Old 01-12-2008, 04:39 PM   #4
Aigarzs
LQ Newbie
 
Registered: Jan 2008
Distribution: Slackware
Posts: 19

Original Poster
Rep: Reputation: 0
Now it works. Thank You!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax error near unexpected token `fi' sureshkumar.repaka Linux - General 7 08-19-2007 11:14 PM
syntax error near unexpected token deskjockey39 Linux - General 2 01-16-2007 09:47 AM
syntax error for unexpected token `(' Steve Spurr Linux - Newbie 6 09-22-2006 09:19 AM
syntax error near unexpected token `else' josedias Programming 3 09-11-2006 08:09 PM
syntax error near unexpected token ` mattyspatty Programming 8 05-07-2006 06:19 PM


All times are GMT -5. The time now is 11:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration