LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   ./script.sh: line 2: syntax error near unexpected token `(' (http://www.linuxquestions.org/questions/programming-9/script-sh-line-2-syntax-error-near-unexpected-token-%60-794800/)

n00balert 03-11-2010 04:02 PM

./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

colucix 03-11-2010 04:11 PM

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.

n00balert 03-11-2010 04:15 PM

I love you.

Quote:

Originally Posted by colucix (Post 3894823)
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.


colucix 03-11-2010 04:22 PM

Wow! :cool:


All times are GMT -5. The time now is 09:48 AM.