help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The strange echo command in makefile, may due to bash 4. Please help


From: Chen Jun (陈军)
Subject: Re: The strange echo command in makefile, may due to bash 4. Please help.
Date: Mon, 21 Dec 2009 09:20:55 +0800
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

Paul Smith wrote:
> On Fri, 2009-12-18 at 14:33 +0800, "Chen Jun (陈军)" wrote:
>   
>> Hi, everyone. I run into a problem today. I have a very simple
>> makefile:
>>
>> -------------
>> all:
>>     @echo -e "line1\n"
>> -------------
>>
>> On openSUSE 11.1, it outputs
>>
>> line1
>>
>> But on Ubuntu 9.10, it outputs
>>
>> -e line1
>>
>> If I execute   echo -e "line1";  directly on Bash command line of both
>> Linux, they both outputs "line1" only. In this case, I know /bin/echo
>> is actually executed.
>>
>> The difference between the two Linux I can speculate is the Bash 
>> version: SUSE has bash 3.2.39, while Ubuntu has 4.0.33 . And GNU make 
>> 3.81 try to use bash'es internal echo command in the  above makefile
>> sample.
>>     
>
> There are various differences.  First, remember GNU make always
> run /bin/sh, it doesn't run /bin/bash.  On opensuse and Red Hat,
> etc., /bin/sh is really bash.
>
> On Ubuntu, /bin/sh is really dash which is a POSIX-compliant shell
> without any of the fancy bash bells and whistles.  The builtin "echo"
> command in dash adheres strictly to the POSIX spec, without any extra
> bash or GNU features like "-e" support.
>
> The next thing is that make is not invoking the shell for this (I don't
> think).  Make has a "fast path" where, if it can see that the recipe is
> sufficiently simple, make won't invoke a shell; instead it will parse
> the command line and use fork/exec directly.  In that case you'll be
> using the executable "echo" and not the builtin "echo".
>
>   
>> So, I'd like to always use external echo in my makefile, but don't let
>> me change every occurrence of "echo" to "/bin/echo". Can somebody
>> help?
>>     
>
> You should just use a portable method, then you won't have to worry
> about whether you're using the system echo, or the building shell echo,
> and which shell you're using.  That's far too painful and error-prone to
> be workable.  If you need to do processing that requires backslash
> escape-type fanciness, you should use printf instead:
>
>       all:
>               @printf 'line1\n'
>
>   
Thank you Paul. You are quite right. But I really don't want to change
that much ubiquitous echos in my makefiles, and I have an idea, on those
system linking /bin/sh to /bin/dash, I would run my makefile as

make SHELL=/bin/bash

so I don't have to modify a bit to my makefiles, right? The only rare
problem may arise is that when some bad guys write ``override
SHELL=/bin/XXXsh'' then export SHELL, but I think almost nobody would do
that. Am I right?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]