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?
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] 삭제
몇 마디 만하겠습니다