[英]Access bash special variable from makefile
I am running: 我在跑步:
» make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
This works, from bash
: 这从
bash
起作用:
$ echo $RANDOM
14522
This does not work: 这不起作用:
$ make echo-random
With Makefile
: 使用
Makefile
:
echo-random:
echo $(RANDOM)
Some questions: 一些问题:
make
use a shell to run commands? make
是否使用shell运行命令? bash
? bash
吗? make
somehow access bash
special env variables? make
某种方式访问bash
特殊的env变量吗? You can invoke bash
with the -c
argument (that tells it the next argument is a command it has to run and exit): 您可以使用
-c
参数调用bash
(告诉bash
下一个参数是它必须运行并退出的命令):
echo-random:
@bash -c 'echo $$RANDOM'
This way, each invocation of make echo-random
starts a new bash
instance that runs the command echo $RANDOM
and it produces the outcome you expect. 这样,每次调用
make echo-random
启动一个新的bash
实例,该实例运行命令echo $RANDOM
并产生您期望的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.