4

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,

1 Answer 1

3

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)_"
Sign up to request clarification or add additional context in comments.

1 Comment

yes. It's shell who "swallow" the spaces, I got it. Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.