Works on command line but not in script

OSX 10.9

I am building a script that evaluates the difference between 2 files. Here is a command that does not work transparently.

Running this command in Terminal yields great results; however when I put that line in a .sh script, I get the errors shown below. Am I doing something silly?

In Terminal:

comm -23 <(sort ~/Desktop/t1.txt) <(sort ~/Desktop/t2.txt)

Outputs (difference between 2 files): 
change
hello mate
hello mate = 3

In Script (by itself):

#!/bin/bash
comm -23 <(sort ~/Desktop/t1.txt) <(sort ~/Desktop/t2.txt)

Outputs: 
line 2: syntax error near unexpected token `('
line 2: `comm -23 <(sort ~/Desktop/t1.txt) <(sort ~/Desktop/t2.txt)'

You are using the script with

sh script

Instead use

bash script

... or make the script executable and and call it directly.

/path/to/script

Then the shebang (the #! characters on the first line) will make sure the proper shell is used

1 Like