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