使文件回显显示“$PATH”细绳

发布于 2024-09-18 16:04:23 字数 441 浏览 8 评论 0原文

我试图强制 make 文件显示下一个字符串:

"Please execute next commands:
setenv PATH /usr/local/greenhills/mips5/linux86:$PATH"

问题出在 "$PATH" 上。命令

@echo "setenv PATH /usr/local/greenhills/mips5/linux86:$PATH"

导致结果

"setenv PATH /usr/local/greenhills/mips5/linux86:ATH"

转义字符、引号、"$(shell echo " 的任何组合都没有得到所需的结果...

有什么建议吗?

I am trying to force make file to display next string:

"Please execute next commands:
setenv PATH /usr/local/greenhills/mips5/linux86:$PATH"

The problem is with "$PATH". Command

@echo "setenv PATH /usr/local/greenhills/mips5/linux86:$PATH"

cause a result

"setenv PATH /usr/local/greenhills/mips5/linux86:ATH"

any combinations of escape characters, quotes, "$(shell echo " didn't get required results...

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

假情假意假温柔 2024-09-25 16:04:24

make 使用 $ 作为自己的 变量扩展。例如,单字符变量 $A 或具有长名称的变量 - ${VAR}$(VAR)

要将 $ 放入命令中,请使用 $$,例如:

all:
  @echo "Please execute next commands:"
  @echo 'setenv PATH /usr/local/greenhills/mips5/linux86:$PATH'

另请注意,要 make "" 和 '' (双引号和单引号)不发挥任何作用,它们会逐字传递到 shell。 (删除 @ 符号以查看 make 发送到 shell 的内容。)为了防止 shell 扩展 $PATH,第二行使用 ''

The make uses the $ for its own variable expansions. E.g. single character variable $A or variable with a long name - ${VAR} and $(VAR).

To put the $ into a command, use the $$, for example:

all:
  @echo "Please execute next commands:"
  @echo 'setenv PATH /usr/local/greenhills/mips5/linux86:$PATH'

Also note that to make the "" and '' (double and single quoting) do not play any role and they are passed verbatim to the shell. (Remove the @ sign to see what make sends to shell.) To prevent the shell from expanding $PATH, second line uses the ''.

腹黑女流氓 2024-09-25 16:04:24

棘手的

Makefile 片段 - 关于如何打印以及如何使用

CURRENTDIR =  $(shell pwd)
PARENTDIR = $(shell dirname $(CURRENTDIR))
#HOME =  ${HOME} No need of this
#PATH = ${PATH} or this

test:
    $(info  HOME is  $(value HOME) PATH is $(value PATH))
    $(info  HOME is  $(HOME) PATH is $(PATH))
    -$(shell unzip xx.zip -d $(HOME)/.local)
    $(export PATH := $(PATH):$(HOME)/.local/bin)

输出

make test

HOME is  /home/alex PATH is /home/alex/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/lib/cuda/bin:/usr/local/go/bin
HOME is  /home/alex PATH is /home/alex/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/lib/cuda/bin:/usr/local/go/bin

Tricky

Makefile snippet - on how to print and how to use

CURRENTDIR =  $(shell pwd)
PARENTDIR = $(shell dirname $(CURRENTDIR))
#HOME =  ${HOME} No need of this
#PATH = ${PATH} or this

test:
    $(info  HOME is  $(value HOME) PATH is $(value PATH))
    $(info  HOME is  $(HOME) PATH is $(PATH))
    -$(shell unzip xx.zip -d $(HOME)/.local)
    $(export PATH := $(PATH):$(HOME)/.local/bin)

Output

make test

HOME is  /home/alex PATH is /home/alex/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/lib/cuda/bin:/usr/local/go/bin
HOME is  /home/alex PATH is /home/alex/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/lib/cuda/bin:/usr/local/go/bin
可爱暴击 2024-09-25 16:04:23

GNU make 手册中,他们在描述函数:

值函数为您提供了一种使用 a 的值的方法
变量而不扩展它。请注意,这并不
撤消已经发生的扩展;例如,如果您创建
一个简单扩展的变量,其值在
定义;在这种情况下,值函数将返回相同的值
结果与直接使用变量相同。

值函数的语法为:

 $(值变量)

注意variable是变量的名称;不是对该变量的引用。因此你通常不会使用
写入时加“$”或括号。 (但是,您可以使用
如果您不希望名称成为变量,则名称中包含变量引用
常数。)

该函数的结果是一个包含以下值的字符串
变量,不发生任何扩展。例如,在这个
生成文件:

<前><代码> FOO = $PATH

全部:
@回声$(FOO)
@echo $(值 FOO)

第一个输出行将是 ATH,因为“$P”将扩展为 make 变量,而第二个输出行将是 ATH
输出行将是 $PATH 环境的当前值
变量,因为值函数避免了扩展。

In the manual for GNU make, they talk about this specific example when describing the value function:

The value function provides a way for you to use the value of a
variable without having it expanded. Please note that this does not
undo expansions which have already occurred; for example if you create
a simply expanded variable its value is expanded during the
definition; in that case the value function will return the same
result as using the variable directly.

The syntax of the value function is:

 $(value variable)

Note that variable is the name of a variable; not a reference to that variable. Therefore you would not normally use
a ‘$’ or parentheses when writing it. (You can, however, use a
variable reference in the name if you want the name not to be a
constant.)

The result of this function is a string containing the value of
variable, without any expansion occurring. For example, in this
makefile:

 FOO = $PATH

 all:
         @echo $(FOO)
         @echo $(value FOO)

The first output line would be ATH, since the “$P” would be expanded as a make variable, while the second
output line would be the current value of your $PATH environment
variable, since the value function avoided the expansion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文