2012-11-12 3 views
4

에 후행 공백은 내가 수동 만들 GNU에서 다음을 읽고 있어요 'make'를 실행할 때메이크 : 변수 값

if you do not want any whitespace characters at the end of your variable value, 
you must remember not to put a random comment on the end of the line after some whitespace, such as this: 

dir := /foo/bar # directory to put the frobs in 
Here the value of the variable dir is ‘/foo/bar ’ (with four trailing spaces), 
which was probably not the intention. (Imagine something like ‘$(dir)/file’ with this definition!) 

내가

foo := hi # four trailing spaces 
all: 
    @echo $(foo)_ 

"다음과 같은 간단한 메이크과 노력, 출력은 '_ 하이'단지 '안녕하세요'사이에 하나 개의 공간이며, 왜 네 개의 공백이 없다?

감사합니다. 밑줄

답변

3

make이이 스크립트를 실행하면 변수를 에코에 전달하지 않고 대신 $(foo)foo의 값으로 바꿉니다.

따라서 실제로 실행되는 스크립트는 echo hi...._입니다 (점은 명확히하기위한 것임).

echo에 대한 인수를 구문 분석 할 때 공백이 무시됩니다.

주위를 큰 따옴표로 묶어 문자열로 출력 할 수 있습니다.

echo "$(foo)_" 
+0

예. 공간을 "삼키려는"셸입니다. 알겠습니다. 고마워요! – password636

+0

질문에 답을 표시하십시오. – xiaoyi