37a940
From c99f320d5c0fd98fe88d9cea5407eb7ad9d50e8a Mon Sep 17 00:00:00 2001
37a940
From: Paul Eggert <eggert@cs.ucla.edu>
37a940
Date: Mon, 4 Apr 2022 23:52:49 -0700
37a940
Subject: zgrep: port to POSIX sed
37a940
MIME-Version: 1.0
37a940
Content-Type: text/plain; charset=UTF-8
37a940
Content-Transfer-Encoding: 8bit
37a940
37a940
* zgrep.in (res): When escaping the file name do not rely on GNU
37a940
sed’s extension to POSIX with respect to s/.../\n/.  Instead, use
37a940
features that should also work with AIX and/or Solaris sed.  This is
37a940
simpler anyway, and would have prevented the recently-fixed bug.
37a940
---
37a940
 zgrep.in | 15 ++++-----------
37a940
 1 file changed, 4 insertions(+), 11 deletions(-)
37a940
37a940
diff --git a/zgrep.in b/zgrep.in
37a940
index bdf7da2..6a16dd1 100644
37a940
--- a/zgrep.in
37a940
+++ b/zgrep.in
37a940
@@ -220,18 +220,11 @@ do
37a940
       case $i in
37a940
       (*'
37a940
 '* | *'&'* | *'\'* | *'|'*)
37a940
-        i=$(printf '%s\n' "$i" |
37a940
-            sed '
37a940
-              :start
37a940
-              $!{
37a940
-                N
37a940
-                b start
37a940
-              }
37a940
-              s/[&\|]/\\&/g
37a940
-              s/\n/\\n/g
37a940
-            ');;
37a940
+          icolon=$(printf '%s\n' "$i:" |
37a940
+                     sed -e 's/[&\|]/\\&/g' -e '$!s/$/\\/');;
37a940
+      (*) icolon="$i:";;
37a940
       esac
37a940
-      sed_script="s|^|$i:|"
37a940
+      sed_script="s|^|$icolon|"
37a940
 
37a940
       # Fail if grep or sed fails.
37a940
       r=$(
37a940
-- 
37a940
cgit v1.1
37a940