与匿名管道一起使用的差异在放入 Makefile 时会出现奇怪的错误

Diff used with anonumous pipes gives strange error when it is put in a Makefile

我尝试在 Makefile 中 运行 'diff',使用匿名管道。不同的结果 比较从 bash shell 和从 Makefile 启动 'diff'。任何澄清?谢谢

$ diff <(echo cat) <(echo dog)
1c1
< cat
---
> dog

$ make
diff <(echo cat) <(echo dog)
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `diff <(echo cat) <(echo dog)'
make: *** [test] Error 2

我的 Makefile 是

test:
        diff <(echo cat) <(echo dog)

如错误消息所示,您的 shell 是 sh 而不是 bash;所以你不能使用 Bash 语法功能。

一个常见的解决方法是设置 SHELL=/bin/bash(或您当地的等效项),或者,当然,将您的代码重构为 POSIX-compliant shell 脚本。