[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: document another sed portability problem
From: |
Ralf Wildenhues |
Subject: |
Re: document another sed portability problem |
Date: |
Mon, 14 Aug 2006 22:44:56 +0200 |
User-agent: |
Mutt/1.5.12-2006-07-14 |
Hello Paul, Bruno,
* Paul Eggert wrote on Mon, Jul 24, 2006 at 09:57:32PM CEST:
> 2006-07-24 Paul Eggert <address@hidden>
>
> * 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
> address@hidden/usr/ucb/sed}) strip leading white space from the text of
> address@hidden, @samp{c}, and @samp{i} commands. Prepend a backslash to
> +work around this incompatibility with Posix:
> +
> address@hidden
> +$ @kbd{echo flushleft | sed -e 'a\}
> address@hidden indented'}
> +flushleft
> +indented
> +$ @kbd{echo foo | sed -e 'a\}
> address@hidden indented'}
> +flushleft
> + indented
> address@hidden 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
- Re: document another sed portability problem,
Ralf Wildenhues <=