我经常找到Bash语法非常有用,例如过程替换,如 diff <(sort file1) <(sort file2)
.
是否可以在 Makefile 中使用这样的 Bash 命令?我在想这样的事情:
file-differences:
diff <(sort file1) <(sort file2) > $@
在我的 GNU Make 3.80 中,这会报错,因为它使用了 shell
而不是 bash
执行命令。
最佳答案
5.3.2 Choosing the Shell
------------------------
The program used as the shell is taken from the variable `SHELL'. If
this variable is not set in your makefile, the program `/bin/sh' is
used as the shell.
所以将 SHELL :=/bin/bash
放在你的 makefile 的顶部,你应该可以开始了。
顺便说一句:您也可以为一个目标执行此操作,至少对于 GNU Make。每个目标都可以有自己的变量赋值,如下所示:
all: a b
a:
@echo "a is $$0"
b: SHELL:=/bin/bash # HERE: this is setting the shell for b only
b:
@echo "b is $$0"
这将打印:
a is /bin/sh
b is /bin/bash
有关详细信息,请参阅文档中的“特定于目标的变量值”。该行可以位于 Makefile 中的任何位置,不必紧接在目标之前。
关于bash - 如何在 Makefile 目标中使用 Bash 语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/589276/