[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: Sed portability (Was: sed usage in autoheader)
From: |
Akim Demaille |
Subject: |
FYI: Sed portability (Was: sed usage in autoheader) |
Date: |
16 Nov 2000 10:45:57 +0100 |
User-agent: |
Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands) |
| > From: Akim Demaille <address@hidden>
| > Date: 15 Nov 2000 16:32:18 +0100
| >
| > Do you mean `s,[^/]*$,,' would work here? Man, how can someone write
| > something that broken :(.
|
| Just for the record, Cray is correct: POSIX does not allow
| `s/[^/]*$//'. `s,[^/]*$,,' is required to work, though.
I'm applying the path below, thanks!
| > Bruce> never, ever use substitution separator
| > Bruce> chars inside of the substitution expressions, period.
|
| I've had good luck with strings like `/foo[\/]bar/' in cases where I
| already know from context that the matched string can't contain `\'.
| That's portable, as it works with both the traditional and the POSIX
| interpretation.
We do agree `/foo[\/]bar/' is a single pattern which matches the
string `foo/bar', right? Then, why do you use the char class here?
Index: ChangeLog
from Akim Demaille <address@hidden>
POSIX doesn't require s/[^/]// to work.
From Paul Eggert and Johan Danielsson.
* doc/autoconf.texi (Limitations of Usual Tools) <sed>:
Reorganize. Document this issue.
* autoupdate.sh (dir): Use `,' as separator instead of `/'
* autoreconf.sh: Likewise.
* autoupdate.sh: Ditto.
Index: autoheader.sh
===================================================================
RCS file: /cvs/autoconf/autoheader.sh,v
retrieving revision 1.87
diff -u -u -r1.87 autoheader.sh
--- autoheader.sh 2000/11/07 17:58:43 1.87
+++ autoheader.sh 2000/11/16 09:49:42
@@ -81,7 +81,7 @@
# Variables.
: address@hidden@}}
-dir=`echo "$0" | sed -e 's/[^/]*$//'`
+dir=`echo "$0" | sed -e 's,[^/]*$,,'`
# We test "$dir/autoconf" in case we are in the build tree, in which case
# the names are not transformed yet.
for autoconf in "$AUTOCONF" \
@@ -293,7 +293,7 @@
# Dump `acconfig.h' but its bottom.
test -r $localdir/acconfig.h &&
- sed -e '/@BOTTOM@/,$d' -e 's/@TOP@//' $localdir/acconfig.h >>$tmp/config.hin
+ sed '/@BOTTOM@/,$d;s/@TOP@//' $localdir/acconfig.h >>$tmp/config.hin
# Dump the templates from `configure.in'.
for verb in `(set) 2>&1 | sed -n -e '/^ac_verbatim/s/^\([^=]*\)=.*$/\1/p' |
sort`; do
Index: autoreconf.sh
===================================================================
RCS file: /cvs/autoconf/autoreconf.sh,v
retrieving revision 1.58
diff -u -u -r1.58 autoreconf.sh
--- autoreconf.sh 2000/11/07 17:58:43 1.58
+++ autoreconf.sh 2000/11/16 09:49:42
@@ -91,7 +91,7 @@
# Variables.
: address@hidden@}}
debug=false
-dir=`echo "$0" | sed -e 's/[^/]*$//'`
+dir=`echo "$0" | sed -e 's,[^/]*$,,'`
force=false
# --install -- as --add-missing in other tools.
install=false
Index: autoupdate.sh
===================================================================
RCS file: /cvs/autoconf/autoupdate.sh,v
retrieving revision 1.44
diff -u -u -r1.44 autoupdate.sh
--- autoupdate.sh 2000/11/07 17:58:43 1.44
+++ autoupdate.sh 2000/11/16 09:49:50
@@ -96,7 +96,7 @@
# Variables.
: address@hidden@}}
: ${SIMPLE_BACKUP_SUFFIX='~'}
-dir=`echo "$0" | sed 's/[^/]*$//'`
+dir=`echo "$0" | sed 's,[^/]*$,,'`
# We test "$dir/autoconf" in case we are in the build tree, in which case
# the names are not transformed yet.
for autoconf in "$AUTOCONF" \
Index: doc/autoconf.texi
===================================================================
RCS file: /cvs/autoconf/doc/autoconf.texi,v
retrieving revision 1.388
diff -u -u -r1.388 autoconf.texi
--- doc/autoconf.texi 2000/11/14 16:01:05 1.388
+++ doc/autoconf.texi 2000/11/16 09:54:11
@@ -5885,8 +5885,26 @@
@item @command{sed}
@cindex @command{sed}
+Patterns should not include the separator (unless escaped), even as part
+of a character class. In conformance with @sc{posix}, the Cray
address@hidden will reject @samp{s/[^/]*$//}: use @samp{s,[^/]*$,,}.
+
+Sed scripts should not use branch labels longer than 8 characters and
+should not contain comments.
+
+Input should have reasonably long lines, since some @command{sed} have
+an input buffer limited to 4000 bytes.
+
+Alternation, @samp{\|}, is common but not portable.
address@hidden FIXME: I know Solaris is guilty, but I don't remember how.
+Anchors (@samp{^} and @samp{$}) inside groups are not portable.
+
+Nested groups are extremely portable, but there is at least one
address@hidden (System V/68 Base Operating System R3V7.1) that does not
+support it.
+
Of course the option @option{-e} is portable, but it is not needed. No
-valid @command{sed} program can start with a dash, so it does not help
+valid Sed program can start with a dash, so it does not help
disambiguating. Its sole usefulness is helping enforcing indenting as
in:
@@ -5905,21 +5923,6 @@
Contrary to yet another urban legend, you may portably use @samp{&} in
the replacement part of the @code{s} command to mean ``what was
matched''.
-
address@hidden scripts should not use branch labels longer than 8
-characters and should not contain comments.
-
address@hidden input should have reasonably long lines, since some
address@hidden have an input buffer limited to 4000 bytes.
-
-Alternation, @samp{\|}, is common but not portable.
-
-Nested groups are extremely portable, but there is at least one
address@hidden (System V/68 Base Operating System R3V7.1) that does not
-support it.
-
-Anchors (@samp{^} and @samp{$}) inside groups are not portable.
address@hidden FIXME: I know Solaris is guilty, but I don't remember how.
@item @command{sed} (@samp{t})
- FYI: Sed portability (Was: sed usage in autoheader),
Akim Demaille <=