This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] libjava: avoid using escape sequence with undefined behaviour in echo


Paolo Bonzini <paolo.bonzini@lu.unisi.ch> writes:

> Matthias Klose wrote:
> 
> >When using ash as system and config shell, the bootstrap fails in libjava,
> >because a wrong Makefile.deps is generated. echo '\1\2' in ash just
> >echoes ^A^B. ash claims that these escape sequences elicit undefined
> >behaviour.
> >
> >This rule was introduced in the 4.0 branch after 4.0.1, before that
> >change libjava used to build using ash, proposing this change for the
> >4.0 branch as well.
> >
> >Ok to checkin?
> >
> I don't oppose such a patch, but still, ash is completely not POSIX
> and this single noncompliancy will break a good percentage of sed
> scripts.

ash is not being POSIX incompliant here.  This is echo, not sed.  In
POSIX terms, echo is a separate command invoked by the shell (of
course, most shells implement echo as a builtin).  Since the
backslashes in this case are quoted with single quotes, the shell will
invoke echo with strings which contain backslashes.  And POSIX.2 says,
about echo, in section 4.19.4, "if any of the operands contain a
backslash (\) character, the results are implementation defined."  The
same text appears in SUSv6.

This is then discussed in the rationale, which explains that this
arises from the difference between the BSD and System V echo programs.
Using echo portably across the two systems requires avoiding backslash
characters.  The rationale recommends using printf, instead (although
of course printf is not as portable as echo).

The X/Open System Interfaces Extension does specify the behaviour of
backslash in an argument to echo when followed by particular letters
(e.g., \n is converted to newline) but oddly does not specify what
should happen if backslash is followed by some random character.

(As it happens, bash is not compliant with XSI by default, as XSI says
that backslash backslash should be transformed to backslash, but in
bash
    echo '\\1'
prints "\\1", not "\1".  bash will do this transformation if you
invoke echo with the -e option, but of course an XSI echo will simply
print that -e.  So no help there.)

Anyhow, I'm not going to take a position on whether we should stop
using backslash with echo.  However, I do think that we shouldn't
disparage ash as not being POSIX compliant when we are invoking
behaviour which is explicitly implementation defined.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]