bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep-2.9.69-f91c on OSF/1


From: Jim Meyering
Subject: Re: grep-2.9.69-f91c on OSF/1
Date: Sat, 12 Nov 2011 15:10:45 +0100

Stefano Lattarini wrote:
> This might cause annoying slow-downs on systems where forks are more
> expensive (i.e., MinGW and Cygwin).  What about doing something like
> this instead, so that the extra forks are avoided when the shell is
> Bash (as is the usual case under MinGW and Cygwin, if I'm not
> mistaken):
>
>   if test -n "$BASH_VERSION"; then
>     export_with_values () { export "$@"; }
>   else
>     export_with_values () { ... your implementation here ... }
>   fi
>
> My testing shows that this idiom should work with at least bash 4.1,
> 3.2, 3.0, 2.05 and 2.0.

I like the idea but prefer to test for the precise feature being replaced.
Then we don't even penalize those who use dash or zsh.

It is tricky, due to the brokenness of Solaris' /bin/sh, but as we
learned via init.sh, you have to eval the test in a sub-shell:

    if (eval "export v=x") 2>/dev/null; then
      export_with_values () { export "$@"; }
    else
      export_with_values () { ... Bruno's implementation here ... }
    fi

I'll do that, but first, a little bug fix:

>From fc5be7ad57aec36d659878e4789ece0667397220 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 12 Nov 2011 15:10:07 +0100
Subject: [PATCH] tests: make the replacement export function more robust

* tests/Makefile.am (sed_quote_value): Also quote single quotes.
Remove sed's -e options.  Not needed.
---
 tests/Makefile.am |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index b8a5a3c..50b5726 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -109,10 +109,10 @@ TESTS_ENVIRONMENT =                               \
   export_with_values ()                                        \
   {                                                    \
     sed_extract_var='s/=.*//';                         \
-    sed_quote_value="s/=\\(.*\\)/='\\1'/";             \
+    sed_quote_value="s/'/'\\\\''/g;s/=\\(.*\\)/='\\1'/";\
     for arg in "$$@"; do                               \
-      var=`echo "$$arg" | sed -e "$$sed_extract_var"`; \
-      arg=`echo "$$arg" | sed -e "$$sed_quote_value"`; \
+      var=`echo "$$arg" | sed "$$sed_extract_var"`;    \
+      arg=`echo "$$arg" | sed "$$sed_quote_value"`;    \
       eval "$$arg";                                    \
       export "$$var";                                  \
     done;                                              \
--
1.7.8.rc0.61.g8a042



reply via email to

[Prev in Thread] Current Thread [Next in Thread]