3

Does it make sense to use shell_qoute from String::ShellQuote when I pass the arguments to system this way?

#!/usr/bin/env perl
use warnings;
use 5.012;
use String::ShellQuote qw(shell_quote);

my $file = shift;
my $argument = shift;

$file = shell_quote $file;
$argument = shell_quote $argument;

system( 'some_command', '--verbose', '-o', $file, $argument );
sid_com
  • 24,137
  • 26
  • 96
  • 187

1 Answers1

4

No it doesn't. If you invoke system as

system LIST

then it doesn't invoke the shell. Shell meta-characters have no special meaning. So you must not quote your arguments, or else it gives the wrong results.

One needs to quote if system is invoked as

system SCALAR

where SCALAR might be something like ls file name with spaces and the argument to ls is a single file name that has spaces.

daxim
  • 39,270
  • 4
  • 65
  • 132
tuxuday
  • 2,977
  • 17
  • 18