[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

OT: Odd Perl (rm?) behavior



I've been pounding my head against the wall for the past hour or so
trying to get this figured out to no avail. I wrote a simple Perl script
to convert filenames with spaces into either filenames with spaces
escaped or quoted filenames. While STDOUT produces the expected results,
when the output is fed to another command (namely rm) the results are
odd. First, here's the Perl script in all its "complexity":

-- Perl --

#!/usr/bin/perl

@files = <STDIN>;

foreach (@files) {
  chomp;
  if ($ARGV[0] ne "--quote") {
    $_ =~ s/ /\\ /g;
  }else {
    $_ = "\"".$_."\"";
  }
  $_ = $_." ";
}

print @files;

-- End Perl --

If I just do something like:

ls /mydir |spcgobble.pl

I get the proper output. Namely a file called "the party.txt" will come
out as "the\ party.txt" suitable for ingestion by rm.

However, if I expand the idea a bit and do:

rm -v `ls /mydir |spcgobble.pl`

I get error messages for files "the" and "party.txt", even though "rm -v
the\ party.txt" works just fine.

In much the same way, rm -v "the party.txt", works just fine, but using
the --quote option in the script which produces "the party.txt" on
STDOUT, I get an error message about "the not being found and party.txt"
not being found. Any suggestions?

-Alex

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: