重击丢失$(HOME)变量 [英] Bash missing $(HOME) variable

查看:57
本文介绍了重击丢失$(HOME)变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Makefile编译应用程序已经有一段时间了,没有任何问题.今天,我意识到我的Makefile不再工作了.进行一些调试后,我很快发现未定义$(HOME)

I have been compiling an application using Makefile for quite a while without any problems. Today, I realized that my Makefile wasn't working any longer. A bit of debugging and I soon found out that $(HOME) was not defined

$echo $(HOME)
-bash: HOME: command not found

我一直认为$HOME$(HOME)可以互换使用.是否有理由可以配置系统以避免使用$(HOME)?

I always thought that $HOME and $(HOME) could be used interchangeably. Is there a reason why a system could be configured to avoid the use of $(HOME)?

推荐答案

它是${HOME},而不是$(HOME).

$(HOME)将扩展为HOME命令的输出.由于(可能)没有这样的命令,您会收到一条错误消息.

$(HOME) would expand to the output of a HOME command. Since there (probably) is no such command, you'll get an error message.

但是,$(HOME)是Makefile中正确的语法.如果您需要调试Makefile的帮助,则需要向我们展示其中的内容,或者,更好的是,出现同样问题的小型Makefile. make规则,例如:

However, $(HOME) is the correct syntax in a Makefile. If you need help debugging your Makefile, you'll need to show us what's in it -- or, better, a small Makefile that exhibits the same problem. A make rule like:

target:
        echo $(HOME)

在运行make target时应打印主目录的路径.

should print the path of your home directory when you run make target.

在外壳中,您可以将HOME变量称为$HOME${HOME};后者可以避免相邻令牌的问题.

In the shell, you can refer to the HOME variable as $HOME or as ${HOME}; the latter can avoid problems with adjacent tokens.

在Makefile中,可以使用$(HOME)${HOME},但是$(HOME)格式更为常见.仅当变量名称为一个字符长时,才可以省略括号(但即使这样,您也应该使用它们来保持清楚). (没有人声称make是清晰直观的语法模型.)

In a Makefile, you can use either $(HOME) or ${HOME}, but the $(HOME) form is more common. You can omit the parentheses only when the variable name is one character long (but even then you should use them for clarity). (Nobody has claimed that make is a model of clear and intuitive syntax.)

这篇关于重击丢失$(HOME)变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆