From: Ralf Wildenhues Date: Tue, 22 Jun 2010 05:29:35 +0000 (+0200) Subject: Further clarification on sed -e portability. X-Git-Tag: v2.66~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fc8e49cd5b3a1894a3ca0d9ffc32b364ae87dc5;p=thirdparty%2Fautoconf.git Further clarification on sed -e portability. See also http://austingroupbugs.net/view.php?id=262 and http://austingroupbugs.net/view.php?id=264. * doc/autoconf.texi (Limitations of Usual Tools) : Clarify more about sed -e and Posix limitations. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 024a8355..c589cce7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-06-22 Ralf Wildenhues + and Eric Blake + + Further clarification on sed -e portability. + * doc/autoconf.texi (Limitations of Usual Tools) : Clarify + more about sed -e and Posix limitations. + 2010-06-22 Bruno Haible Document how to use literal newlines in makefile rules. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 10609554..35c40c89 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -18253,13 +18253,14 @@ but Posix says that this use of a semicolon has undefined effect if should use semicolon only with simple scripts that do not use these verbs. -The argument of the @option{-e} option must be a syntactically complete -script. GNU @command{sed} allows to pass multiple script fragments, -each as argument of a separate @option{-e} option, that are then combined, -with newlines between the fragments. A future Posix revision may allow -this as well. But in Posix:2008, this is not allowed, and the -@command{sed} programs on Solaris 10, HP-UX 11, and AIX don't allow it -either: +Posix up to the 2008 revision requires the argument of the @option{-e} +option to be a syntactically complete script. GNU @command{sed} allows +to pass multiple script fragments, each as argument of a separate +@option{-e} option, that are then combined, with newlines between the +fragments, and a future Posix revision may allow this as well. This +approach is not portable with script fragments ending in backslash; for +example, the @command{sed} programs on Solaris 10, HP-UX 11, and AIX +don't allow splitting in this case: @example $ @kbd{echo a | sed -n -e 'i\} @@ -18269,11 +18270,23 @@ $ @kbd{echo a | sed -n -e 'i\' -e 0} Unrecognized command: 0 @end example -Commands inside @{ @} brackets are further restricted. Posix says that +@noindent +In practice, however, this technique of joining fragments +through @option{-e} works for multiple @command{sed} functions within +@samp{@{} and @samp{@}}, even if that is not specified by Posix: + +@example +@c The quote around the closing brace silences interactive zsh. +$ @kbd{echo a | sed -n -e '/a/@{' -e s/a/b/ -e p -e '@}'} +b +@end example + +Commands inside @{ @} brackets are further restricted. Posix 2008 says that they cannot be preceded by addresses, @samp{!}, or @samp{;}, and that each command must be followed immediately by a newline, without any intervening blanks or semicolons. The closing bracket must be alone on -a line, other than white space preceding or following it. +a line, other than white space preceding or following it. However, a +future version of Posix may standardize the use of addresses within brackets. Contrary to yet another urban legend, you may portably use @samp{&} in the replacement part of the @code{s} command to mean ``what was