Skip to content

Commit 531671f

Browse files
authored
grep: add -R alias for -r
* On *BSD, there's no difference between grep -r and grep -R, so adding -R in this version allows for greater compatibility * Also add missing validation: $pattern can be undefined when shifting off ARGV, and it's a fatal error if we get no patterns (found with "perl grep -r")
1 parent f9f8b9f commit 531671f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

bin/grep

+7-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use File::Spec;
5454
use File::Temp qw();
5555
use Getopt::Std;
5656

57-
our $VERSION = '1.016';
57+
our $VERSION = '1.017';
5858

5959
$| = 1; # autoflush output
6060

@@ -88,7 +88,7 @@ sub VERSION_MESSAGE {
8888

8989
sub usage {
9090
die <<EOF;
91-
usage: $Me [-IincwsxvHhLlFguraqT] [-e pattern] [-A NUM] [-B NUM] [-C NUM]
91+
usage: $Me [-IincwsxvHhLlFguRraqT] [-e pattern] [-A NUM] [-B NUM] [-C NUM]
9292
[-m NUM] [-f pattern-file] [pattern] [file...]
9393
9494
Options:
@@ -243,8 +243,9 @@ sub parse_args {
243243
}
244244
@ARGV = @tmparg;
245245

246-
getopts('IinC:cwsxvHhLlguraqTFZm:A:B:', \%opt) or usage();
246+
getopts('IinC:cwsxvHhLlguRraqTFZm:A:B:', \%opt) or usage();
247247

248+
$opt{'r'} ||= $opt{'R'};
248249
if (defined $opt{'m'} && $opt{'m'} !~ m/\A[0-9]+\z/) {
249250
die "$Me: invalid max count\n";
250251
}
@@ -261,6 +262,7 @@ sub parse_args {
261262

262263
unless (length $pattern) {
263264
$pattern = shift @ARGV;
265+
usage() unless defined $pattern;
264266
push @patterns, $pattern;
265267
}
266268
unless ($no_re) {
@@ -544,7 +546,7 @@ grep - search for regular expressions and print
544546
545547
=head1 SYNOPSIS
546548
547-
grep [-IincwsxvhHlLFiguraqT] [-e pattern] [-A NUM] [-B NUM] [-C NUM]
549+
grep [-IincwsxvhHlLFiguRraqT] [-e pattern] [-A NUM] [-B NUM] [-C NUM]
548550
[-m NUM] [-f pattern-file] [pattern] [file ...]
549551
550552
=head1 DESCRIPTION
@@ -660,7 +662,7 @@ value of the Perl magic scalar $. (whose documentation is in L<perlvar>).
660662
661663
Suppress diagnostic messages to the standard error.
662664
663-
=item B<-r>
665+
=item B<-R> and B<-r>
664666
665667
Recursively scan directories. This option causes B<grep> to
666668
descend directories in a left-first, depth-first manner and search

0 commit comments

Comments
 (0)