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
:
$ echo $RANDOM
14522
This does not work:
$ make echo-random
With Makefile
:
echo-random:
echo $(RANDOM)
Some questions:
make
use a shell to run commands? bash
? make
somehow access bash
special env variables? You can invoke bash
with the -c
argument (that tells it the next argument is a command it has to run and exit):
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.