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

Amaan Cheval amaan.cheval at gmail.com
Sun Mar 11 04:36:19 UTC 2018


"echo -e" only tells the echo command to enable interpretation of
backslashes. The string there doesn't actually use any, so it can do
without the flag - if I changed this to printf, I couldn't think of a
reason not to change all the other "echo" instances to printf as well.

If that's a welcome change, I'm happy to send a patch for it!

On Sun, Mar 11, 2018 at 9:50 AM Chris Johns <chrisj at rtems.org> wrote:

> I know this has already been pushed but ...

> On 10/3/18 2:55 am, Amaan Cheval 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"

> "echo -e" to "printf" - OK

> >            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"

> "echo -e" to "echo" - Why is this change not using "printf"?

> >          fi
> >        done
> >      done

> Chris



More information about the devel mailing list