LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-09-2010, 01:16 AM   #1
rc5gd
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Rep: Reputation: 0
bash: syntax error near unexpected token `('


Hi all,

I am new to this forum. I am sorry if this is not correct place to post this.

I was trying to run small shell script, but could not run. I got the error like in subject. Can any one help me to figure this problem.

This is exact way i was trying to do.

[mycom7] # ./ctopo.sh um_test1 [(1,2),(2,1)]
bash: syntax error near unexpected token `('

ctopo.sh script takes two strings as input, here first one is um_test1 and second one is [(1,2),(2,1)]. Then it passes to the python script it takes two strings.

#!/bin/bash

slice=$1
links=$2
exec `/usr/bin/plcsh /root/gra2.py $slice $links`


Thank you
--Ram
 
Old 07-09-2010, 01:29 AM   #2
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
Paratheses are, amongst others, shell meta-characters with special meaning to the shell. If you want to pass them as-is to a script or executable, you have to tell the shell to ignore them when evaluating your command by escaping or quoting them. In your case, the best way is to double-quote the whole second parameter.
 
Old 07-09-2010, 05:25 PM   #3
DaneM
Member
 
Registered: Oct 2003
Location: Chico, CA, USA
Distribution: Linux Mint
Posts: 745

Rep: Reputation: 81
Might it also work to quote the variables in the shell script, like this?

Code:
exec `/usr/bin/plcsh /root/gra2.py "$slice" "$links"`
--Dane
 
Old 07-09-2010, 05:41 PM   #4
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
No. The shell interprets the command you are typing, ( and ) are characters with a special meaning for the shell, so you MUST hide them by quoting or by escaping.
 
Old 07-10-2010, 02:37 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
Another piece of advice when writing a script is to test and ask yourself, how would this work on the command line?

So to take your script, ask yourself if the following would work:
Code:
/usr/bin/plcsh /root/gra2.py um_test1 [(1,2),(2,1)]
Then test it on the command line to confirm.
 
Old 07-11-2010, 12:37 AM   #6
rc5gd
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you very much for all your replies. Currently i can not reach my server(remote one, on which i am trying to integrate my application ) to test these solutions, i guess there is a network issue.

I will get back to you soon.

Hi Grail. Thank you for your advice. I will definitely mark it as solved, if these solutions work.
 
Old 07-13-2010, 09:54 PM   #7
rc5gd
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you all. It is solved with double quote the second parameter like..

[mycom7] # ./ctopo.sh um_test1 "[(1,2),(2,1)]"
 
  


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
[SOLVED] bash: syntax error near unexpected token `else' lucmove Programming 9 05-10-2010 10:03 PM
bash: syntax error near unexpected token `(' Folklore Linux - Newbie 1 05-02-2010 04:35 AM
-bash: syntax error near unexpected token ty1on Linux - Newbie 3 08-26-2009 03:19 PM
syntax error near unexpected token in bash using perl kambrish Programming 21 07-03-2007 01:42 PM
Trouble with Bash -- syntax error near unexpected token `fi' anamericanjoe Programming 5 05-19-2006 03:59 PM


All times are GMT -5. The time now is 07:14 AM.

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