Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String::ShellQuote: when do I need `shell_quote`?

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 );
like image 855
sid_com Avatar asked Dec 01 '25 14:12

sid_com


1 Answers

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.

like image 190
tuxuday Avatar answered Dec 04 '25 15:12

tuxuday