Busybox build problem

Brion Finlay brion.finlay at gmail.com
Sat Feb 3 20:02:41 UTC 2007


I agree Paul, I wasn't sure that dash was/wasn't compliant.  It is the
default with the latest Ubuntu for /bin/sh, which means busybox builds don't
work on Ubuntu by default.

Since the question was raised about posix compliance, I decided to go look
it up.  Here is what I found:

Here are the posix specs:
(free registration required)

Here is the main link:
http://www.unix.org/single_unix_specification/

here are some direct links:
http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html#tag_02_02
http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html#tag_02_06_03
http://www.opengroup.org/onlinepubs/000095399/utilities/echo.html

Here are some excerpts for consideration:

2.6.3 Command Substitution
"Within the backquoted style of command substitution, backslash shall retain
its literal meaning, except when followed by: '$', '`', or '\' (dollar sign,
backquote, backslash).
...
A single-quoted or double-quoted string that begins, but does not end,
within the "`...`" sequence produces undefined results."

so a single " or ' is undefined behavior within a backquote command
substitution and cannot be escaped with a backslash.

echo:
"It is not possible to use *echo* portably across all POSIX systems unless
both *-n* (as the first argument) and escape sequences are omitted."

"The following operands shall be supported:
*string*A string to be written to standard output. If the first operand is *
-n*, or if any of the operands contain a backslash ( '\' ) character, the
results are implementation-defined....
    \nWrite a <newline>....
"

So in the POSIX specs, the echo operand is not necessarily quoted, and a
"\n" is SUPPOSED to be printed as a newline, unless the "-n" option is used
(in which case backslash escapes are implementation specific), so according
to the spec technically bash and bbox ash are non-compliant because they
print the \n instead of the newline.

"New applications are encouraged to use
*printf*<http://www.opengroup.org/onlinepubs/009695399/utilities/printf.html>instead
of
*echo*."
"

The *echo* utility has not been made obsolescent because of its extremely
widespread use in historical applications. Conforming applications that wish
to do prompting without <newline>s or that could possibly be expecting to
echo a *-n*, should use the
*printf*<http://www.opengroup.org/onlinepubs/009695399/utilities/printf.html>utility
derived from the Ninth Edition system.

As specified, *echo* writes its arguments in the simplest of ways. The two
different historical versions of *echo* vary in fatally incompatible ways.

The BSD *echo* checks the first argument for the string *-n* which causes it
to suppress the <newline> that would otherwise follow the final argument in
the output.

The System V *echo* does not support any options, but allows escape
sequences within its operands, as described for XSI implementations in the
OPERANDS section.

The *echo* utility does not support Utility Syntax Guideline 10 because
historical applications depend on *echo* to echo *all* of its arguments,
except for the *-n* option in the BSD version.

"
Regardless of all of this (or perhaps this is a good demonstration) -
quoting is complicated and it is probably a good idea to avoid it when
possible.  An echo "`...`" command substitution seems a little like calling
"a = strtofloat(floattostr(b));" instead of directly "a=b;"


On 2/3/07, Paul Fox <pgf at brightstareng.com> wrote:
>
> vapier wrote:
> > On Saturday 03 February 2007, Brion Finlay wrote:
> > > The fix that could be made to scripts/mkconfigs in order to work more
> > > generally
> >
> > another fix would be to use a POSIX compliant shell ... then there
> wouldn't
> > be problem
> > -mike
> >
>
> we had the same problem with a different build system when we
> moved it to ubuntu.  i did some googling at the time, but
> couldn't find a definitive answer -- i expected to find a lot of
> discussion on it somewhere in ubuntu-land, since it's a pretty
> big change, but i didn't.  it's not clear to me that dash isn't
> posix compliant, at least with regard to echo's expanding '\n'.
> but it might not be.  is there a "dash is/isn't POSIX" discussion
> page out there anywhere?
>
> in our case it was expedient (and safe) to simply replace
> "#!/bin/sh" with "#!/bin/bash", but that's probably not
> appropriate for busybox.
>
> paul
> =---------------------
> paul fox, pgf at brightstareng.com
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://busybox.net/cgi-bin/mailman/listinfo/busybox
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/busybox/attachments/20070203/e179b110/attachment-0001.htm 


More information about the busybox mailing list