Reputation: 57
I have the following question:
When I execute the following script directly in a terminal window, the commands behave as expected.
$ diff <(echo tmp) <(echo tmp1)
1c1
< tmp
---
> tmp1
However when I write the same command in a shell script
#! /bin/bash
diff <(echo tmp) <(echo tmp1)
I get the following error message:
$ sh test.sh
test.sh: line 2: syntax error near unexpected token `('
test.sh: line 2: ` diff <(echo tmp) <(echo tmp1)'
Initially I thought this was an issue with diff, but this also happens with other commands. Does anybody have an idea what causes the problem?
Upvotes: 2
Views: 1927
Reputation: 11837
When bash is invoked using sh
, it starts up in a special, POSIX-compliant mode. This has different syntax, which I guess explains the different results.
See bashref of POSIX mode, #22: "process substitution is not available".
Upvotes: 1
Reputation: 75724
That syntax doesn't look familiar. Are you sure you are using bash in your terminal? You can verify by typing echo $SHELL
.
Upvotes: 0
Reputation: 455152
Try
bash test.sh
or
chmod ugo+x test.sh
./test.sh
Works fine for me when I do either.
Looks like the syntax is not supported by the bourne shell (sh).
Upvotes: 5