diff options
author | wosch <wosch@FreeBSD.org> | 1997-12-07 01:00:56 +0000 |
---|---|---|
committer | wosch <wosch@FreeBSD.org> | 1997-12-07 01:00:56 +0000 |
commit | 0252661afad64e2dbc101829171fab4957e52da9 (patch) | |
tree | 65229e29f1949d2c71c1ee06ea0b20a9e24be35b /gnu/usr.bin/gzip | |
parent | 0ac774a20f55fe28b97a90fcca590790c298fde1 (diff) | |
download | FreeBSD-src-0252661afad64e2dbc101829171fab4957e52da9.zip FreeBSD-src-0252661afad64e2dbc101829171fab4957e52da9.tar.gz |
Use getopts instead getopt(1). This should fix the problem
with whitespaces in pattern.
PR: 5211
Diffstat (limited to 'gnu/usr.bin/gzip')
-rw-r--r-- | gnu/usr.bin/gzip/zgrep.getopt | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/gnu/usr.bin/gzip/zgrep.getopt b/gnu/usr.bin/gzip/zgrep.getopt index 1c138f4..58564b3 100644 --- a/gnu/usr.bin/gzip/zgrep.getopt +++ b/gnu/usr.bin/gzip/zgrep.getopt @@ -26,7 +26,7 @@ # # zgrep - search possibly compressed files for a regular expression # -# $Id: zgrep.getopt,v 1.4 1997/02/22 15:46:11 peter Exp $ +# $Id: zgrep.getopt,v 1.5 1997/04/19 20:06:57 wosch Exp $ PATH=/bin:/usr/bin:$PATH; export PATH @@ -39,20 +39,20 @@ case "$0" in esac gzip=gzip gzipopt="-cdfq" pattern= grepopt= files= line= header= -set -- `getopt "0123456789A:B:CEFGVX:bce:f:hiLlnqsvwxy" "$@"` # check options -while : +while getopts "0123456789A:B:CEFGVX:bce:f:hiLlnqsvwxy" option do - case "$1" in - --) shift; break;; # EOF options - -e|-f) pattern="$1 $2"; shift;; # -f file - -l|-L) line=$1; grepopt="$grepopt $1";; - -h|-q) header=$1; grepopt="$grepopt $1";; - *) grepopt="$grepopt $1";; # rest + case "$option" in + e|f) pattern="-$option $OPTARG";; # -f file + l|L) line=-$option; grepopt="$grepopt -$option";; + h|q) header=-h; grepopt="$grepopt -$option";; + # rest + [0-9CEFGVbchiLlnqsvwxy]) grepopt="$grepopt -$option";; + [ABXef]) grepopt="$grepopt -$option $OPTARG";; esac - shift done +shift $(($OPTIND - 1)) # check pattern case X"$pattern" in @@ -67,29 +67,28 @@ files="$@" # no shell loop neccessary for option -q or -h # and a single file or reading from stdin case "$header"X"$#" in - -h*|-q*|X0|X1) $gzip $gzipopt -- $files | $grep $grepopt -- $pattern + -h*|-q*|X0|X1) $gzip $gzipopt -- $files | $grep $grepopt -- "$pattern" exit $?;; esac - -exit=1 for f in $files do case "$line" in - -l|-L) if $gzip $gzipopt -- $f | - $grep $grepopt -- $pattern >/dev/null - then - echo $f - fi - ;; - *) $gzip $gzipopt -- $f | $grep $grepopt -- $pattern | - sed "s%^%${f}:%";; - esac + -l) if $gzip $gzipopt -- $f | + $grep $grepopt -- "$pattern" >/dev/null + then + echo $f + fi + ;; + -L) if $gzip $gzipopt -- $f | + $grep $grepopt -- "$pattern" >/dev/null; then : + else + echo $f + fi + ;; - case $? in - 2) exit=$?;; - 0) case "$exit" in 2);; 1) exit=0;; esac;; + *) $gzip $gzipopt -- $f | $grep $grepopt -- "$pattern" | + sed "s%^%${f}:%" + ;; esac done - -exit $exit |