Bash在Makefile中异常!

Li *_*ong 5 bash makefile make

全部,

我发现相同的 Makefile 在 Mac OS X 中运行良好,但在 Ubuntu 中不起作用。片段如下:

start:
    @echo $(seperator)
    @if [[ "$(PROJECT)" == "" ]]; then \
         echo " Project powered by CodeMate!"; \
     else \
         echo "  $(PROJECT)"; \
     fi
    @echo $(seperator)
Run Code Online (Sandbox Code Playgroud)

提出抱怨:

/bin/sh: [[: not found
Run Code Online (Sandbox Code Playgroud)

任何的想法?

干杯,


更新:

我已将上述条件 Bash 语句更改为:

if test "$(PROJECT)" = ""; then \
Run Code Online (Sandbox Code Playgroud)

然后一切正常。那么“[[”有什么问题呢?

Rob*_*low 9

把它放在你的顶部Makefile

SHELL := /bin/bash # Use bash syntax
Run Code Online (Sandbox Code Playgroud)

发生这种情况是因为[[是一个内置命令,bash并且您正在使用sh. 上面的行将设置bash为在 makefile 上运行的命令的默认解释器。


enz*_*tib 7

Makefilessh默认使用,而不是bash.

在 Ubuntu 中,sh指向dashPOSIX 兼容且简约的 shell,不提供[[密钥。