sub escape_shell {
my $line=shift;
# This list is from _Unix in a Nutshell_. (except '#')
- $line~s/([\s!"\$()*+#;<>?@\[\]\\`|~])/\\$1/g;
+ $line=~s/([\s!"\$()*+#;<>?@\[\]\\`|~])/\\$1/g;
return $line;
}
# The kernel can accept command lines up to 20k worth of characters.
my $command_max=20000; # LINUX SPECIFIC!!
+ # I could use POSIX::ARG_MAX, but that would be slow.
# Figure out length of static portion of command.
my $static_length=0;
}
# Reads in the specified file, one word at a time, and returns an array of
-# the result. Pass in a true value for the second parameter if the contents
-# of the file are filenames that can be glob expanded.
+# the result. If a value is passed in as the second parameter, then glob
+# expansion is done in the directory specified by the parameter ("." is
+# frequently a good choice).
sub filearray {
my $file=shift;
- my $doglob=shift || '';
+ my $globdir=shift;
my @ret;
- open (DH_FARRAY_IN,"<$file") || error("cannot read $file: $1");
+ open (DH_FARRAY_IN, $file) || error("cannot read $file: $1");
while (<DH_FARRAY_IN>) {
# Only do glob expansion in v3 mode.
- if ($doglob && compat(3)) {
- push @ret, map glob, split;
+ #
+ # The tricky bit is that the glob expansion is done
+ # as if we were in the specified directory, so the
+ # filenames that come out are relative to it.
+ if (defined $globdir && ! compat(2)) {
+ for (map { glob "$globdir/$_" } split) {
+ s#^$globdir/##;
+ push @ret, $_;
+ }
}
else {
push @ret, split;