How to use long variables name in Makefile?

Zen

Today I'm learning make command, and I find it seems can execute any bash command by reading Makefile on current directory.

However, I encountered a problem. That when using variables, it seems that system will only read the first character of the variable.

Below is my file and running result:

# FILE CONTENT
Z="zen_on_the_moon"
now=$(date)

fun:
    touch $Z
    echo $now
    echo "file created on" $now >> $Z

# RUNNING IT
=>make fun
touch "zen_on_the_moon"
echo ow
ow
echo "file created on" ow >> "zen_on_the_moon"

How should I use the variable now in the Makefile under fun item?

cuonglm

In Makefile, you refer to a variable by using syntax $(var_name). Using $var_name cause the first character other than a dollar sign $, open parenthesis ( or open brace { treated as variable name.

In $now, you actually get content of variable $n followed by literal string ow.

So you need:

$(now)

to get the content of variable named now.

Also note that now=$(date) get the content of variable named date instead of result of command date. You need to use shell function:

now=$(shell date)

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to use wildcard in Makefile?

분류에서Dev

How to use variable with ':' in a Makefile?

분류에서Dev

How can I use function arguments where variables exist with the same name?

분류에서Dev

How long can the name of a type constructor be?

분류에서Dev

How to have variables of one included makefile available in another makefile included later?

분류에서Dev

How to use Monit Environment variables?

분류에서Dev

AngularJS - How to use includes with variables?

분류에서Dev

How to use find command with variables

분류에서Dev

How long can i use WSAPI 1.42

분류에서Dev

How to use variables to create elements in an array in BASH?

분류에서Dev

how to use system environment variables in boto

분류에서Dev

How do I use URL directories as variables?

분류에서Dev

How to use variables inside back-quotes

분류에서Dev

How long can I use Windows 10 without activation?

분류에서Dev

How to use a defined name in an array in my code?

분류에서Dev

How to use jquery to find xml element with ':' in name?

분류에서Dev

How can i use $_POST if the name is a variable?

분류에서Dev

How to use attribute name stored in variable?

분류에서Dev

R: How to use $ when the name is stored in a variable?

분류에서Dev

How to use dynamic variable name in nodejs

분류에서Dev

Recode from a long list of variables

분류에서Dev

Can you use breakpoint in Makefile?

분류에서Dev

How to make perl Makefile.PL use a given C compiler when compiling an XS module?

분류에서Dev

How to define subroutines in a Makefile

분류에서Dev

How to put this command in a Makefile?

분류에서Dev

make clean results in no target with specific makefile name

분류에서Dev

How to use objects for storing global variables? Best practice

분류에서Dev

How to use $GLOBALS to share variables across php files?

분류에서Dev

How use Forward declaration in clojure and unbound variables across namespace

Related 관련 기사

  1. 1

    How to use wildcard in Makefile?

  2. 2

    How to use variable with ':' in a Makefile?

  3. 3

    How can I use function arguments where variables exist with the same name?

  4. 4

    How long can the name of a type constructor be?

  5. 5

    How to have variables of one included makefile available in another makefile included later?

  6. 6

    How to use Monit Environment variables?

  7. 7

    AngularJS - How to use includes with variables?

  8. 8

    How to use find command with variables

  9. 9

    How long can i use WSAPI 1.42

  10. 10

    How to use variables to create elements in an array in BASH?

  11. 11

    how to use system environment variables in boto

  12. 12

    How do I use URL directories as variables?

  13. 13

    How to use variables inside back-quotes

  14. 14

    How long can I use Windows 10 without activation?

  15. 15

    How to use a defined name in an array in my code?

  16. 16

    How to use jquery to find xml element with ':' in name?

  17. 17

    How can i use $_POST if the name is a variable?

  18. 18

    How to use attribute name stored in variable?

  19. 19

    R: How to use $ when the name is stored in a variable?

  20. 20

    How to use dynamic variable name in nodejs

  21. 21

    Recode from a long list of variables

  22. 22

    Can you use breakpoint in Makefile?

  23. 23

    How to make perl Makefile.PL use a given C compiler when compiling an XS module?

  24. 24

    How to define subroutines in a Makefile

  25. 25

    How to put this command in a Makefile?

  26. 26

    make clean results in no target with specific makefile name

  27. 27

    How to use objects for storing global variables? Best practice

  28. 28

    How to use $GLOBALS to share variables across php files?

  29. 29

    How use Forward declaration in clojure and unbound variables across namespace

뜨겁다태그

보관