Search code examples
linuxshellcomm

Shell comm parameters issue


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


Solution

  • 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