【问题标题】:String::ShellQuote: when do I need `shell_quote`?String::ShellQuote: 我什么时候需要`shell_quote`?
【发布时间】:2012-05-22 16:31:03
【问题描述】:

当我以这种方式将参数传递给system 时,使用String::ShellQuote 中的shell_qoute 是否有意义?

#!/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 );

【问题讨论】:

    标签: perl shell system argument-passing


    【解决方案1】:

    不,它没有。如果你调用system

    system LIST
    

    那么它就不会调用 shell。 Shell 元字符没有特殊含义。所以你不能引用你的论点,否则它会给出错误的结果。

    如果system被调用为需要引用

    system SCALAR
    

    其中 SCALAR 可能类似于 ls file name with spaces,而 ls 的参数是包含空格的单个文件名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      • 2018-02-25
      • 1970-01-01
      • 2012-09-16
      • 1970-01-01
      • 2010-10-15
      相关资源
      最近更新 更多