需要有关如何转义此perl命令的帮助

0 perl command escaping system

我试图在perl中执行此命令,它从bash工作正常.但是从perl执行时,它不起作用.也许我没有逃过正确的角色?能否请你帮忙.

my $comp_command = "./jnx_comp.py <(/usr/bin/ssh $boss\@$ftpServer[$j] '/bin/cat $compList[0]') <(/usr/bin/ssh $boss\@$ftpServer[$j] '/bin/cat $compList[1]')"

my $result = `$comp_command`;
Run Code Online (Sandbox Code Playgroud)

以下是运行脚本时给出的错误:

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `./jnx_comp.py <(/usr/bin/ssh jnxapps@dcsftp01n '/bin/cat /home/A11256/out/recon/JNX_EOD_20130606.csv'
Run Code Online (Sandbox Code Playgroud)

ike*_*ami 5

使用时它工作正常,bash因为它是一个有效的bash命令.

使用Perl 执行时它不起作用,sh因为它不是有效的sh命令.

如果要执行bash命令,则需要实际执行bash.

my $result = `bash -c bash_commmand_here`;
Run Code Online (Sandbox Code Playgroud)

让我们解决一些插值问题.

use String::ShellQuote qw( shell_quote );

my $remote_cmd1 = shell_quote('/bin/cat', $compList[0]);
my $remote_cmd2 = shell_quote('/bin/cat', $compList[1]);

my $ssh_cmd1 = shell_quote('/usr/bin/ssh', "$boss\@$ftpServer[$j]", $remote_cmd1);
my $ssh_cmd2 = shell_quote('/usr/bin/ssh', "$boss\@$ftpServer[$j]", $remote_cmd2);

my $bash_cmd = "./jnx_comp <( $ssh_cmd1 ) <( $ssh_cmd2 )";

my $sh_cmd = shell_quote('bash', '-c', $bash_cmd);

`$sh_cmd`
Run Code Online (Sandbox Code Playgroud)