Skip to content

Commit 500e24e

Browse files
authored
grep: make space after -e or -f optional (#816)
* BSD and GNU versions do not require a space between -e/-f and the option argument * This version did not raise an error, but option arguments without a space resulted in incorrect behaviour * Remove -e and -f from getopts() option string because they are handled earlier * test1: perl grep -e0 -e 1 ar ---> patterns 0 and 1 in file ar * test2: grep -fwordlist.txt.old -f pat1 xargs ---> patterns from file wordlist.txt.old and pat1, searching against file xargs
1 parent 8509f78 commit 500e24e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

bin/grep

Lines changed: 6 additions & 6 deletions
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.014';
57+
our $VERSION = '1.015';
5858

5959
$| = 1; # autoflush output
6060

@@ -219,13 +219,13 @@ sub parse_args {
219219
my @tmparg;
220220
while (@ARGV) {
221221
my $arg = shift @ARGV;
222-
if ($arg eq '-e') {
223-
$pattern = shift @ARGV;
222+
if ($arg =~ s/\A\-e//) {
223+
$pattern = length($arg) ? $arg : shift(@ARGV);
224224
usage() unless defined $pattern;
225225
push @patterns, $pattern;
226226
}
227-
elsif ($arg eq '-f') {
228-
my $file = shift @ARGV;
227+
elsif ($arg =~ s/\A\-f//) {
228+
my $file = length($arg) ? $arg : shift(@ARGV);
229229
usage() unless defined $file;
230230
die "$Me: $file: is a directory\n" if -d $file;
231231
my $fh;
@@ -246,7 +246,7 @@ sub parse_args {
246246
@ARGV = @tmparg;
247247

248248
$opt{'p'} = $opt{'P'} = ''; # argument to print()
249-
getopts('IinC:cwsxvHhe:f:LlgurpP:aqTFZm:A:B:', \%opt) or usage();
249+
getopts('IinC:cwsxvHhLlgurpP:aqTFZm:A:B:', \%opt) or usage();
250250

251251
if (defined $opt{'m'} && $opt{'m'} !~ m/\A[0-9]+\z/) {
252252
die "$Me: invalid max count\n";

0 commit comments

Comments
 (0)