[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Severe performance problem and proposed solution
From: |
Paul Eggert |
Subject: |
Re: Severe performance problem and proposed solution |
Date: |
Wed, 27 Feb 2002 05:34:59 -0800 (PST) |
> From: Akim Demaille <address@hidden>
> Date: 27 Feb 2002 10:05:42 +0100
> What we want, is to find a reliable `echo', or any means that would
> help us remove the thousands of heredocs we have.
> elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then
> # Yippee, $echo works!
Unfortunately this approach won't work in the long run.
POSIX 1003.2-1992 allows echo '\t' to output backslash-t, but
POSIX 1003.1-2001 requires that it must output a tab character.
Eventually shells will head in that direction, albeit reluctantly.
Here's an idea. How about if we use expr instead of cat? That is
allowed by the GNU coding standards, and it handles backslash
correctly. That is, instead of doing this:
cat <<__ACEOF
some very
long string
with funny characters "'\\
and with $SHELL expansions in it
__ACEOF
we do this:
expr "Xsome very
long string
with funny characters \"'\\
and with $SHELL expansions in it" : 'X\(.*\)'
If __ACEOF is quoted, the expr version should use ' instead of ",
and should quote ' rather than " of course.
The problems I see with this approach are:
* expr may be limited in the length of the string that it can handle.
But we already have this problem with some extent with __ACEOF;
and we already use expr in similar ways so there is some precedent.
* " is tricky, e.g.
cat <<__ACEOF
${foo+"abc"}
__ACEOF
will be mishandled if we blindly escape all "s in the expr version.
But that is a problem no matter what program we substitute for
__ACEOF.
* expr exits with nonzero status if the string is empty. But we're
already ignoring the exit status of cat, so I don't see this as a
real problem.
- Re: Severe performance problem and proposed solution, (continued)
- Re: Severe performance problem and proposed solution, Zack Weinberg, 2002/02/25
- Re: Severe performance problem and proposed solution, Zack Weinberg, 2002/02/25
- Re: Severe performance problem and proposed solution, Ralf Corsepius, 2002/02/26
- Re: Severe performance problem and proposed solution, Zack Weinberg, 2002/02/26
- Re: Severe performance problem and proposed solution, Ralf Corsepius, 2002/02/26
Re: Severe performance problem and proposed solution, Zack Weinberg, 2002/02/26