添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
独立的跑步鞋  ·  如何从 Python ...·  1 年前    · 
大力的枕头  ·  String.getBytes和new ...·  1 年前    · 
勤奋的风衣  ·  exception in thread ...·  1 年前    · 

Linux - 环境变量$HOME与$(HOME)

4 人关注

最近我不得不在 .bashrc 中更新我的JAVA环境变量。

echo $JAVA_HOME # 打印出/usr/java/...

echo $(JAVA_HOME) # 引发错误 "无法找到 JAVA_HOME 命令"

我担心我的make文件,即使用 $(JAVA_HOME) 的文件将无法工作,因为 $JAVA_HOME 被识别,而不是 $(JAVA_HOME)

我怎样才能让 $(JAVA_HOME) 等于 $JAVA_HOME ,目前已经设置了。另外,为什么会出现这种情况?

1 个评论
如果我记得不错的话,在makefiles中没有这样的问题,因为$(WHATEVER)的形式是由make本身处理的
linux
environment-variables
Kevin Meredith
Kevin Meredith
发布于 2010-08-20
6 个回答
Quentin
Quentin
发布于 2010-08-20
已采纳
0 人赞同

make is not bash

它们处理变量的方式不同。替换代码2】是你如何读取一个叫做 foo 在bash中, $(foo) 是你在makefile中读取它的方式。

Matthew Slattery
Matthew Slattery
发布于 2010-08-20
0 人赞同

More precisely:

  • JAVA_HOME is a shell variable; assuming it has been exported with export , it is then an environment variable.
  • $JAVA_HOME is the bash syntax to expand the shell variable named JAVA_HOME .
  • In bash , $(command) substitutes the output of command -- so $(JAVA_HOME) is trying to run a command called JAVA_HOME , hence the error you got.
  • When make starts up, it looks at each environment variable and sets a make variable of the same name to the same value. (See http://www.gnu.org/software/make/manual/make.html#Environment .)
  • $(JAVA_HOME) is the make syntax to expand the make variable named JAVA_HOME .
  • 所以你的 Makefile 应该可以正常工作。 $(JAVA_HOME) 扩展了 make 的变量 JAVA_HOME 。它被设置为环境变量 JAVA_HOME 的值(除非你的 Makefile 故意做了一些事情来覆盖它),它有正确的值。

    paulsm4
    paulsm4
    发布于 2010-08-20
    0 人赞同

    问:我的制作文件会不会读取环境 变量吗?如果我在.bashrc中定义$JAVA_HOME 的话,我的 make 文件会不会正确读取 $(JAVA_HOME)是否正确?

    答:是的,绝对的:)

    muhmuhten
    muhmuhten
    发布于 2010-08-20
    0 人赞同

    make会将其变量设置为环境。(反之则不成立)。

    Peter Tillemans
    Peter Tillemans
    发布于 2010-08-20
    0 人赞同