LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-11-2010, 05:02 PM   #1
n00balert
LQ Newbie
 
Registered: Mar 2010
Distribution: CentOS, Ubuntu
Posts: 2

Rep: Reputation: 0
./script.sh: line 2: syntax error near unexpected token `('


Okay, first off I'm no hotshot programmer (and actually lack much familiarity with shell scripting) so apologies in advance if this problem is so trivial as to be irritating.

What I'm trying to do is drop the following command from either a shell script or a perl program. However, while it executes fine and does what it's supposed to when entered from the command line, I can't get it to work as a system call.

Here's the line:

Code:
/usr/bin/comm -23 <(/bin/sort /home/me/backup/latest.tmp | /usr/bin/uniq ) <( sort /home/me/tb/backup/yesterday.tmp | /usr/bin/uniq ) > /home/me/tb/backup/new
When I drop it from a shell script like this:
Code:
#!/bin/sh
/usr/bin/comm -23 <(/bin/sort /home/me/backup/latest.tmp | /usr/bin/uniq ) <( sort /home/me/tb/backup/yesterday.tmp | /usr/bin/uniq ) > /home/me/tb/backup/new
I get the following:
Code:
./script.sh: line 2: syntax error near unexpected token `('
./script.sh: line 2: `/usr/bin/comm -23 <(/bin/sort /home/me/backup/latest.tmp | /usr/bin/uniq ) <( sort /home/me/tb/backup/yesterday.tmp | /usr/bin/uniq ) > /home/me/tb/backup/new'
If I try escaping the ()s with \ or ', I get this:
Code:
./script.sh: line 2: (/bin/sort: No such file or directory
./script.sh: line 2: (: No such file or directory
/usr/bin/uniq: ): No such file or directory
I've tried a bunch of other stuff to get it working (deleting the ()s, spacing them differently, etc) and looked around online for a solution, but I can't find anything that works.

I tried a shell script directly only after anything I tried to drop it from perl with `` or system() failed with the same errors.

Not to be a rude dick, but I'd appreciate it if anyone who wants to suggest a solution test it first, as I don't know how much more failure I can handle.

Distro info (if it matters)
Code:
Linux version 2.6.18-164.el5PAE (mockbuild@builder16.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Thu Sep 3 04:10:44 EDT 2009
 
Old 03-11-2010, 05:11 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
The problem is here:
Code:
#!/bin/sh
when invoked as /bin/sh, the bash shell acts most likely as the old Bourne shell (essentially for compatibility reasons). In this case, process substitution is not a valid construct anymore. You can either change the she-bang to read #!/bin/bash or the logic of the command line.
 
1 members found this post helpful.
Old 03-11-2010, 05:15 PM   #3
n00balert
LQ Newbie
 
Registered: Mar 2010
Distribution: CentOS, Ubuntu
Posts: 2

Original Poster
Rep: Reputation: 0
Thumbs up

I love you.

Quote:
Originally Posted by colucix View Post
The problem is here:
Code:
#!/bin/sh
when invoked as /bin/sh, the bash shell acts most likely as the old Bourne shell (essentially for compatibility reasons). In this case, process substitution is not a valid construct anymore. You can either change the she-bang to read #!/bin/bash or the logic of the command line.
 
Old 03-11-2010, 05:22 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Wow!
 
  


Reply

Tags
bash, errors, shell


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
why is my shell script giving me - syntax error near unexpected token 'enterInfo() chisunum Linux - Newbie 3 10-23-2009 04:37 PM
syntax error near unexpected token `else' alex0 Programming 7 07-28-2009 09:01 AM
sh: syntax error near unexpected token `(' venkatesh_b Linux - Newbie 1 05-16-2009 06:44 AM
syntax error near unexpected token -what does this mean? rmnature Linux - Newbie 5 02-14-2009 09:19 AM
syntax error near unexpected token `else' josedias Programming 3 09-11-2006 08:09 PM


All times are GMT -5. The time now is 04:00 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