- fix --.
- fix -e. - fix patterns starting with -. - fix "missing argument" message.
This commit is contained in:
parent
6957cc2e13
commit
2553980909
@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# $NetBSD: zgrep,v 1.4 2004/05/25 07:09:09 mrg Exp $
|
||||
# $NetBSD: zgrep,v 1.5 2006/05/03 16:48:29 yamt Exp $
|
||||
#
|
||||
# Copyright (c) 2003 Thomas Klausner.
|
||||
#
|
||||
@ -32,6 +32,7 @@ zcat=/usr/bin/zcat
|
||||
endofopts=0
|
||||
pattern_found=0
|
||||
grep_args=""
|
||||
hyphen=0
|
||||
|
||||
prg=$0
|
||||
|
||||
@ -51,28 +52,31 @@ do
|
||||
case $1 in
|
||||
# from GNU grep-2.5.1 -- keep in sync!
|
||||
-[ABCDXdefm])
|
||||
if [ $# -lt 2 ]
|
||||
then
|
||||
echo "${prg}: missing argument for $1 flag" >&2
|
||||
exit 1
|
||||
fi
|
||||
case $1 in
|
||||
-e)
|
||||
pattern_found=1;;
|
||||
pattern="$2"
|
||||
pattern_found=1
|
||||
shift 2
|
||||
break
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $# -lt 2 ]
|
||||
then
|
||||
echo "${prg}: missing argument for ${saved_arg} flag" >&2
|
||||
exit 1
|
||||
fi
|
||||
grep_args="${grep_args} $1 $2"
|
||||
shift 2
|
||||
;;
|
||||
--)
|
||||
grep_args="${grep_args} $1"
|
||||
shift
|
||||
endofopts=1
|
||||
;;
|
||||
-)
|
||||
endofopts=1
|
||||
hyphen=1
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
grep_args="${grep_args} $1"
|
||||
@ -88,25 +92,27 @@ done
|
||||
# if no -e option was found, take next argument as grep-pattern
|
||||
if [ ${pattern_found} -lt 1 ]
|
||||
then
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
if [ $# -ge 1 ]; then
|
||||
pattern="$1"
|
||||
shift
|
||||
elif [ ${hyphen} -gt 0 ]; then
|
||||
pattern="-"
|
||||
else
|
||||
echo "${prg}: missing pattern" >&2
|
||||
exit 1
|
||||
fi
|
||||
pattern=$1
|
||||
shift
|
||||
fi
|
||||
|
||||
# call grep ...
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
# ... on stdin
|
||||
${zcat} -fq - | ${grep} ${grep_args} "${pattern}" -
|
||||
${zcat} -fq - | ${grep} ${grep_args} -- "${pattern}" -
|
||||
else
|
||||
# ... on all files given on the command line
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
${zcat} -fq -- "$1" | ${grep} -H --label="${1}" "${pattern}" ${grep_args} -
|
||||
${zcat} -fq -- "$1" | ${grep} -H --label="${1}" ${grep_args} -- "${pattern}" -
|
||||
shift
|
||||
done
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user