سؤال

I'm reading the following in GNU make manual:

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!)

I tried with a simple makefile as below"

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

when executing 'make', the output is just 'hi _', only one space between 'hi' and underscore. Why there are no four spaces?

Thanks,

هل كانت مفيدة؟

المحلول

When make executes this script, it doesn't pass a variable to the echo, but instead replaces $(foo) with foo's value.

So the actual script executed is echo hi...._ (dots are for clarification).

And the white spaces just ignored when parsing the arguments for echo.

You can put double quotes around to make it output as a string.

echo "$(foo)_"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top