grep "-H" option (print the filename for each match) always prints

filenames whether "-h" option (suppress filenames when multiple files
are searched) is speficied or not.

Make zgrep "-h" option actually works with using "-H" option only
when "-h" is not specified.
This commit is contained in:
nakayama 2008-04-27 09:27:55 +00:00
parent a8706a45b4
commit 66f1c31a47
1 changed files with 10 additions and 2 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# $NetBSD: zgrep,v 1.5 2006/05/03 16:48:29 yamt Exp $
# $NetBSD: zgrep,v 1.6 2008/04/27 09:27:55 nakayama Exp $
#
# Copyright (c) 2003 Thomas Klausner.
#
@ -33,6 +33,7 @@ endofopts=0
pattern_found=0
grep_args=""
hyphen=0
silent=0
prg=$0
@ -78,6 +79,10 @@ do
hyphen=1
shift
;;
-h)
silent=1
shift
;;
-*)
grep_args="${grep_args} $1"
shift
@ -110,9 +115,12 @@ then
${zcat} -fq - | ${grep} ${grep_args} -- "${pattern}" -
else
# ... on all files given on the command line
if [ ${silent} -lt 1 ]; then
grep_args="-H ${grep_args}"
fi
while [ $# -gt 0 ]
do
${zcat} -fq -- "$1" | ${grep} -H --label="${1}" ${grep_args} -- "${pattern}" -
${zcat} -fq -- "$1" | ${grep} --label="${1}" ${grep_args} -- "${pattern}" -
shift
done
fi