Last active
March 11, 2020 00:55
-
-
Save moccos/4696088 to your computer and use it in GitHub Desktop.
[Perl] GNU find wrapper to set -regextype.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
my $idx = 0; | |
my @preopt = ("-H", "-L", "-P"); | |
my $command = "find"; | |
my $regex_type = " -regextype posix-egrep"; | |
# check @preopt | |
for (; $idx <= $#ARGV; $idx++) { | |
my $matched = 0; | |
foreach(@preopt) { | |
if ($_ eq $ARGV[$idx]) { | |
$matched++; | |
last; | |
} | |
} | |
last if ($matched == 0); | |
$command .= " " . $ARGV[$idx]; | |
} | |
# check path | |
if (substr($ARGV[$idx], 0, 1) ne "-") { | |
$command .= " " . $ARGV[$idx]; | |
$idx++; | |
} | |
# concatenate regextype option and remaining | |
$command .= $regex_type; | |
for (; $idx <= $#ARGV; $idx++) { | |
if (substr($ARGV[$idx], 0, 1) ne "-") { | |
$command .= " '$ARGV[$idx]'"; | |
} else { | |
$command .= " $ARGV[$idx]"; | |
} | |
} | |
system($command); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment