@@ -97,22 +97,20 @@ sub usage {
97
97
usage: $Me [-incCwsxvhlF1HurtpaqT] [-e pattern]
98
98
[-f pattern-file] [-P sep] [pattern] [file...]
99
99
100
- Standard grep options :
100
+ Options :
101
101
-i case insensitive
102
102
-n number lines
103
103
-c give count of lines matching
104
104
-C ditto, but >1 match per line possible
105
105
-w word boundaries only
106
- -s silent mode
106
+ -q quiet; nothing is written to standard output
107
107
-x exact matches only
108
108
-v invert search sense (lines that DON'T match)
109
109
-h hide filenames
110
110
-e expression (for exprs beginning with -)
111
111
-f file with expressions
112
112
-l list filenames matching
113
113
-F search for fixed strings (disable regular expressions)
114
-
115
- Specials:
116
114
-1 1 match per file
117
115
-H highlight matches
118
116
-u underline matches
@@ -121,7 +119,7 @@ Specials:
121
119
-p paragraph mode (default: line mode)
122
120
-P ditto, but specify separator, e.g. -P '%%\\ n'
123
121
-a all files, not just plain text files
124
- -q quiet about failed file and dir opens
122
+ -s suppress errors for failed file and dir opens
125
123
-T trace files as opened
126
124
127
125
May use GREP_OPTIONS environment variable to set default options.
@@ -146,7 +144,6 @@ sub parse_args {
146
144
@opt { split //, $nulls } = (' ' ) x length ($nulls );
147
145
148
146
getopts(' incCwsxvhe:f:l1HurtpP:aqTF' , \%opt ) or usage();
149
- $opt {' s' } = 1 if $opt {' c' };
150
147
$Mult = 1 if ($opt {' r' } || @ARGV > 1 || @ARGV > 0 && -d $ARGV [0]) && !$opt {' h' };
151
148
152
149
my $no_re = $opt {F } || ( $Me =~ / \b fgrep\b / );
@@ -244,7 +241,6 @@ sub parse_args {
244
241
$opt {1 } += $opt {l }; # that's a one and an ell
245
242
$opt {H } += $opt {u };
246
243
$opt {c } += $opt {C };
247
- $opt {1 } += $opt {' s' } && !$opt {c }; # that's a one
248
244
249
245
$match_code .= ' study;' if @patterns > 5; # might speed things up a bit
250
246
@@ -291,7 +287,7 @@ FILE: while ( defined( $file = shift(@_) ) ) {
291
287
my $compressed = 0;
292
288
293
289
if ( $file eq ' -' ) {
294
- warn " $Me : reading from stdin\n " if -t STDIN && !$opt -> {' q ' };
290
+ warn " $Me : reading from stdin\n " if -t STDIN && !$opt -> {' s ' };
295
291
$name = ' <STDIN>' ;
296
292
}
297
293
elsif ( -d $file ) {
@@ -306,7 +302,7 @@ FILE: while ( defined( $file = shift(@_) ) ) {
306
302
next FILE;
307
303
}
308
304
unless ( opendir ( DIR, $file ) ) {
309
- unless ( $opt -> {' q ' } ) {
305
+ unless ( $opt -> {' s ' } ) {
310
306
warn " $Me : can't opendir $file : $! \n " ;
311
307
$Errors ++;
312
308
}
@@ -332,7 +328,7 @@ FILE: while ( defined( $file = shift(@_) ) ) {
332
328
else {
333
329
$name = $file ;
334
330
unless ( -e $file ) {
335
- warn qq( $Me : "$file " does not exist\n ) unless $opt -> {' q ' };
331
+ warn qq( $Me : "$file " does not exist\n ) unless $opt -> {' s ' };
336
332
$Errors ++;
337
333
next FILE;
338
334
}
@@ -366,7 +362,7 @@ FILE: while ( defined( $file = shift(@_) ) ) {
366
362
else {
367
363
$ok = open $fh , ' <' , $file ;
368
364
}
369
- if ( !$ok && !$opt -> {' q ' } ) {
365
+ if ( !$ok && !$opt -> {' s ' } ) {
370
366
warn " $Me : $file : $! \n " ;
371
367
$Errors ++;
372
368
}
@@ -394,12 +390,12 @@ FILE: while ( defined( $file = shift(@_) ) ) {
394
390
}
395
391
396
392
print (" $name \n " ), next FILE if $opt -> {l };
397
-
398
- $opt -> { ' s ' } || print $Mult && " $name :" ,
393
+ my $showmatch = ! $opt -> { ' q ' } && ! $opt -> { ' c ' };
394
+ $showmatch && print $Mult && " $name :" ,
399
395
$opt -> {n } ? " $. :" : " " , $_ ,
400
396
( $opt -> {p } || $opt -> {P } ) && ( ' -' x 20 ) . " \n " ;
401
397
402
- next FILE if $opt -> {1 }; # that's a one
398
+ next FILE if (! $opt -> {' c ' } && $opt -> { ' 1 ' } || $opt -> { ' q ' }); # single match
403
399
}
404
400
}
405
401
continue {
@@ -524,10 +520,9 @@ $/ scalar. See L<perlvar>.
524
520
Paragraph mode. This causes B<grep > to set Perl's magic $/ to C<'' > .
525
521
(Note that the default is to process files in line mode.) See L<perlvar> .
526
522
527
- =item B<-q >
523
+ =item B<-s >
528
524
529
- Quiet mode. Suppress diagnostic messages to the standard error. See
530
- B<-s > .
525
+ Suppress diagnostic messages to the standard error.
531
526
532
527
=item B<-r >
533
528
@@ -538,11 +533,11 @@ presence of B<-r> implies a file argument of F<.>, the current
538
533
directory, if the user does not provide filenames on the command line.
539
534
See L<"EXAMPLES"> .
540
535
541
- =item B<-s >
536
+ =item B<-q >
542
537
543
- Silent mode. Do not write to the standard output. This option would
538
+ Quiet mode. Do not write to the standard output. This option would
544
539
be useful from a shell script, for example, if you are only interested
545
- in whether or not there exists a match for a pattern. See also B< -q > .
540
+ in whether or not there exists a match for a pattern.
546
541
547
542
=item B<-T >
548
543
0 commit comments