'=' 的转义字符是什么? GNU make 中的符号?
我想通过将环境变量 CPU_TYPE
及其值 -mcpu=603
作为命令行参数传递给该 makefile 来调用 makefile。我正在输入以下命令
make -f make_file CPU_TYPE=-mcpu=603
但它给出了错误,因为环境变量值具有 =
符号。如何在环境值中转义这个等号。
注意:我无法在 make_file
中添加此环境变量或任何其他变量。我必须仅将其作为命令行参数传递。
I want to call a makefile by passing the environment variable CPU_TYPE
and its value -mcpu=603
as command line argument to that makefile. I am entering the below command
make -f make_file CPU_TYPE=-mcpu=603
But its given error because environment variable value is having =
symbol. How to escape this equal symbol in the environment value.
Note : I cant add this environment variable or any other variable inside make_file
. I have to pass it as command line arugments only.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不太可能
应该不会有任何问题,但也许您遇到了很少使用的 shell 功能。
如果您在正在运行的 shell 中使用
set -k
或使用sh -k
运行 shell,它会将任何看起来像环境变量的内容视为环境变量。您可能已经知道,C shell 系列以外的 shell 可以通过在命令之前添加环境变量来为单个命令设置环境变量:
命令本身会看到修改后的环境; shell 对
cmdname
的搜索不会改变。但是,在set -k
生效后,任何看起来像环境变量的变量都会被视为环境变量:例如,您可以使用
env
作为命令来验证这一点。有充分的理由(例如 dd 命令)不将此设置为默认行为。反对这个假设
反对这个假设,我不知道有哪个 shell 会反对环境值中的“
=
”。如果有这样的限制,那就太麻烦了。普通 GNU Make 是可以的
但是,我可以这样做:
并且,在
set -k
生效的情况下,我还可以这样做:在这两种情况下,编译都会采用通过命令行指定的值覆盖 makefile 中的设置。
make
看不到单引号;当然,它们会被外壳去除。你完全可以忽略它们,我得到相同的结果。我在 MacOS X 上使用 bash 运行,但我希望在任何使用任何标准 POSIX-ish shell(Bourne、Korn、Bash)的类 Unix 系统上得到相同的结果。Improbable possibility
There shouldn't be any problem, but maybe you are running afoul of a seldom-used shell feature.
If you use
set -k
in a running shell, or usesh -k
to run a shell, it will treat anything that looks like an environment variable as an environment variable.You probably already know that shells other than the C shell family can set an environment variable for a single command by adding it before the command:
The command itself sees the modified environment; the shell's search for
cmdname
is not altered. However, withset -k
in effect, anything that looks like an environment variable is treated as one:You can validate this by using
env
, for example, as the command. There are sound reasons (such as thedd
command) for not making this the default behaviour.Against the hypothesis
Against this hypothesis, I don't know of a shell that objects to the '
=
' in the environment value. It would be a nuisance if there was such a restriction.Plain GNU Make is OK
However, I'm able to do:
and, with
set -k
in effect, I can also do:In both cases, the compilation takes the value specified via the command line as overriding what is set in the makefile.
The single quotes aren't seen by
make
; they are removed by the shell, of course. You can perfectly well omit them and I get the same result. I'm running usingbash
on MacOS X, but I'd expect the same results on any Unix-like system using any of the standard POSIX-ish shells (Bourne, Korn, Bash).尝试用\=代替=。 本教程显示您提供了一些示例,但不包含如何转义等号。
try \= instead of =. this tutorial shows you some examples but dosnt contain how to escape the equal symbol.
我不确定是否有直接的方法来实现你想要的。
但也许您可以修改您的Makefile,以便它通过例如读取文件来设置
CPU_TYPE
。您可以在make_file
中放入类似的内容,然后使用eg创建一个文件
my603.cputype
,最后运行 make 作为
I'm not sure there is a direct way to achieve what you want.
But perhaps you might modify your Makefile so that it sets the
CPU_TYPE
by e.g. reading a file. You might put in yourmake_file
something likeand then create a file
my603.cputype
with e.g.and finally run make as