Hello Paul, Bruno,

* Paul Eggert wrote on Mon, Jul 24, 2006 at 09:57:32PM CEST:
> 2006-07-24  Paul Eggert  <[EMAIL PROTECTED]>
> 
>       * doc/autoconf.texi (Limitations of Usual Tools): Warn about
>       sed stripping leading white space from text.  From Bruno
>       Haible.

> --- autoconf.texi     24 Jul 2006 19:35:50 -0000      1.1064
> +++ autoconf.texi     24 Jul 2006 19:55:45 -0000      1.1065

> @@ -13671,6 +13671,23 @@ Also note that Posix requires that the @
>  On the other hand, no white space is allowed between @samp{:} and the
>  subsequent label name.
>  
> +Some @command{sed} implementations (e.g., MacOS X 10.4, Solaris 10
> [EMAIL PROTECTED]/usr/ucb/sed}) strip leading white space from the text of
> [EMAIL PROTECTED], @samp{c}, and @samp{i} commands.  Prepend a backslash to
> +work around this incompatibility with Posix:
> +
> [EMAIL PROTECTED]
> +$ @kbd{echo flushleft | sed -e 'a\}
> [EMAIL PROTECTED]   indented'}
> +flushleft
> +indented
> +$ @kbd{echo foo | sed -e 'a\}
> [EMAIL PROTECTED]   indented'}
> +flushleft
> +   indented
> [EMAIL PROTECTED] example
> +
> +

Ouch, there seem more severe issues here.  For one, OpenBSD 3.9 sed does
the same stripping of leading white space.  But also it does not add a
newline to the text argument of the `a' command (the `echo X' is to help
the shell/terminal not eat the incomplete last line in the output):

$ echo 'foo
foo' | sed -e 'a\
bar'; echo X
foo
barfoo
barX
$

I don't if the above behavior is forbidden by Posix; if yes, I can file
a bug upstream.  FWIW, UNICOS sed behaves similarly.


More worryingly though, Tru64 5.1 sed does not parse the examples at
all.  Weirdly, it seems that the `a' command does not work right after
the `-e' option:

$ echo foo | sed -e 'a
bar'
sed: Function a cannot be parsed.
$ echo foo | sed 'a\
bar'
foo
bar
$ echo foo | sed -e 'p;a\
bar'
foo
foo
bar
$ echo foo | sed -e '
a\
bar'
foo
bar
$

So it seems adding a newline before `a', or adding another one of the
few commands allowed to be followed by `;' (in cases where one of these
is applicable) helps.  Simply prepending `;' works on Tru64, but is of
course not portable.

What a mine field!

Cheers,
Ralf


Reply via email to