0

I have an issue running a shell script with parameters. This command running directly on Linux works:

comm -13 <(sort /tmp/f1.txt) <(sort /tmp/f2.txt) > /tmp/f3.txt

If I am trying to run this shell script with this command sending the parameters and I am getting the error below:

test.sh: line 6: syntax error near unexpected token `('
'est.sh: line 6: `comm -13 <(sort $1) <(sort $2) > $3

Here is my shell code:

#!/bin/bash
comm -13 <(sort $1) <(sort $2) > $3

I run it with the following command:

sh test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt

I have ran out of ideas what might be wrong. Please assist.

Thank you, -Andrey

Andrey
  • 1,808
  • 1
  • 16
  • 28
  • 1
    `sh` is not `bash` `<(...)` is a bash feature. Don't use `sh` to run the script. Use `bash`. – Etan Reisner Jun 25 '15 at 15:50
  • 1
    The reason probably is that whatever `sh` on your system means it doesn't support [process substitution](https://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html#Process-Substitution). Why did you put `#!/bin/bash` in your script and use `sh` to execute it? See this: https://www.gnu.org/software/bash/manual/html_node/Major-Differences-From-The-Bourne-Shell.html – Arkadiusz Drabczyk Jun 25 '15 at 15:53
  • This worked. Thanks a lot guys. – Andrey Jun 25 '15 at 16:58

1 Answers1

1

Solutions:

  1. Since you have specified bash in the script's shebang, why do you call it with sh? Simply run ./test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt

  2. Use bash explicitly: bash test.sh /tmp/f1.txt /tmp/f2.txt /tmp/f3.txt

Eugeniu Rosca
  • 5,177
  • 16
  • 45