[PATCH] bootstrap: Use printf instead of echo -e for POSIX shells

Amaan Cheval amaan.cheval at gmail.com
Fri Mar 9 17:00:59 UTC 2018


On Fri, Mar 9, 2018 at 9:47 PM Joel Sherrill <joel at rtems.org> wrote:

> Can you file a ticket for this? It seems like something which should be
> considered for release branches.

Sure. Here it is:
https://devel.rtems.org/ticket/3328

Note, however, that the use of "echo -e" was introduced in 2afb22b,
to remove the make preinstall step[1], so it isn't in any of the current
releases as far as I can tell, only on master.

[1] https://devel.rtems.org/ticket/3254#comment:78


> What shell(s)/host(s) did this show up on?

I use zsh on Ubuntu 16.04 LTS (4.4.0-78-generic x86_64 GNU/Linux),
but since #!/bin/sh is specified in bootstrap, my use of zsh (which does
support -e) is negated by my built-in sh.

The "-e" option may or may not be present even on sh or bash, apparently:
https://unix.stackexchange.com/questions/88307/escape-sequences-with-echo-e-in-different-shells#comment131955_88310


> Thanks.

> --joel

> On Fri, Mar 9, 2018 at 9:55 AM, Amaan Cheval <amaan.cheval at gmail.com>
wrote:

>> On POSIX compliant shells, echo does not have the -e option.
>> This causes the "-e" to be echoed as well, causing potential buggy
>> build processes.

>> Example shell session:

>> -> % sh
>> $ echo -e "foo bar"
>> -e foo bar
>> $

>> According to POSIX, "\$" should be fine regardless due to the use of
>> double-quotes[1]. However, since printf is recommended over echo anyway,
>> we replace "echo -e" with printf where required.

>> [1]
http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_02_03
>> ---
>>   bootstrap | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)

>> diff --git a/bootstrap b/bootstrap
>> index eb6d4fc8f3..b94fa244ce 100755
>> --- a/bootstrap
>> +++ b/bootstrap
>> @@ -152,7 +152,7 @@ headers)
>>             if test x$d != x. ; then
>>               am_dir=`echo $dir | sed 's%[/-]%_%g'`
>>               am_dir="_$am_dir"
>> -            echo -e "\ninclude${am_dir}dir = \$(includedir)/$dir" >>
"$tmp"
>> +            printf "\ninclude${am_dir}dir = \$(includedir)/$dir\n" >>
"$tmp"
>>             else
>>               am_dir=""
>>               echo "" >> "$tmp"
>> @@ -161,7 +161,7 @@ headers)
>>           fi
>>           echo "include${am_dir}_HEADERS += $inc$j" >> "$tmp"
>>           if test $j = bsp.h ; then
>> -          echo -e "include_HEADERS += include/bspopts.h" >> "$tmp"
>> +          echo "include_HEADERS += include/bspopts.h" >> "$tmp"
>>           fi
>>         done
>>       done
>> --
>> 2.13.0

>> _______________________________________________
>> devel mailing list
>> devel at rtems.org
>> http://lists.rtems.org/mailman/listinfo/devel



More information about the devel mailing list