【问题标题】:$${HOME} or ${HOME} in Makefile?Makefile 中的 $${HOME} 或 ${HOME}?
【发布时间】:2018-11-17 22:51:29
【问题描述】:
$ cat Makefile 
all:
    echo VAR is ${HOME}
    echo VAR is $${HOME}

给予

$ make
echo VAR is /home/abc
VAR is /home/abc
echo VAR is ${HOME}
VAR is /home/abc

为什么echo VAR is ${HOME} 语法在 Makefile 中有效?我想,要使用 shell 变量,你必须使用 $${HOME}}

【问题讨论】:

    标签: linux bash shell makefile environment-variables


    【解决方案1】:

    是和不是。最好使用$$ 明确。但是,there is a special rule for environment variables

    make 中的变量可以来自 make 运行的环境。 make 在启动时看到的每个环境变量都会转换为具有相同名称和值的 make 变量。但是在 makefile 中的显式赋值,或者使用命令参数,会覆盖环境。 (如果指定了 `-e' 标志,则环境中的值会覆盖 makefile 中的分配。请参阅选项摘要部分。但这不是推荐的做法。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 2011-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-25
      相关资源
      最近更新 更多