Skip to content

Instantly share code, notes, and snippets.

@moccos
Last active March 11, 2020 00:55
Show Gist options
  • Save moccos/4696088 to your computer and use it in GitHub Desktop.
Save moccos/4696088 to your computer and use it in GitHub Desktop.
[Perl] GNU find wrapper to set -regextype.
#!/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