I am trying to have my Makefile echo text without the trailing new line, but am unable to. I am experiencing the behavior on OS X (on Linux everything works as expected).
Makefile
a:
@echo -n "hello"
b:
@echo -n hello
c:
@/bin/echo -n "hello"
Output:
$make a
-n hello
$make b
hello$make c
hello$
In other words, the make a is broken. What exactly is happening? Is make using a built-in echo? Clearly the presence of the double quotes changes the behavior, but why?
Update
As discovered by @chepner, using the full path to /bin/echo in the makefile understands the -n flag correctly.
Something about the quotes confuses
make. Your code behaves the same for me, but the following works as expected:Hardcoding the path to the executable also works:
The Mac OS X man page for
echo, while discussing the existence of shell built-inechos, mentions that theechoofsh(1)does not support the-noption, but that fails to explain (to me, anyway) why my first alternative works.Confirmation that
makeis usingshto execute the commands by default. Make manual 5.3.2 Choosing the Shell specifies this hehavrior:In
both echo statements behave the same (no newlines printed). So without that variable, we have
bashpretending to besh, but evaluating the two lines differently. Question 1: why? Question 2: is the second line the nativebashecho or/bin/echo, rather than the emulatedshecho?