7 glob - Expand shell-wildcard patterns
11 glob [I<OPTIONS>] [--] I<PATTERN> [I<PATTERN> [I<PATTERN> [...]]]
15 Expand I<PATTERN> as shell-wildcard patterns and output matching filenames.
16 Output all matched file names once and sorted alphabetically.
24 Output filenames as NULL byte temrinated strings.
28 Fail if can not read a directory.
29 See B<GLOB_ERR> in File::Glob(3perl).
33 Fail if any I<PATTERN> did not match.
34 Exit code is 2 in this case.
38 Match case-insensitively.
39 Default is case-sensitive.
43 Support curly bracket expansion.
44 See B<GLOB_BRACE> in File::Glob(3perl).
50 Uses perl(1)'s B<bsd_glob> function from File::Glob(3perl),
54 File::Glob(3perl), perldoc(1): glob
60 use Getopt
::Long qw
/:config no_ignore_case no_bundling no_getopt_compat no_auto_abbrev require_order/;
63 no if ($] >= 5.018), 'warnings' => 'experimental::smartmatch';
65 $OptNullTerminated = 0;
66 $OptGlobFlags = File
::Glob
::GLOB_QUOTE
| File
::Glob
::GLOB_TILDE
;
70 '0' => \
$OptNullTerminated,
71 'f' => sub { $OptGlobFlags |= File
::Glob
::GLOB_ERR
; },
72 'i' => sub { $OptGlobFlags |= File
::Glob
::GLOB_NOCASE
; },
73 'b' => sub { $OptGlobFlags |= File
::Glob
::GLOB_BRACE
; },
74 'E' => \
$OptFailNoMatch,
75 'help' => sub { pod2usage
(-exitval
=>0, -verbose
=>99); },
76 '<>' => sub { unshift @ARGV, @_[0]; die '!FINISH'; },
77 ) or pod2usage
(-exitval
=>2, -verbose
=>99);
82 for my $pattern (@ARGV)
84 my @matches = File
::Glob
::bsd_glob
($pattern, $OptGlobFlags);
85 if(File
::Glob
::GLOB_ERROR
)
87 die "$0: $!: $pattern\n";
89 exit 2 if $OptFailNoMatch and not @matches;
90 %Files = (%Files, map {$_=>1} @matches);
94 $\
= chr 0 if $OptNullTerminated;
95 print "$_" for sort keys %Files;