我试图在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`;
以下是运行脚本时给出的错误:
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'
答案 0 :(得分:5)
使用bash
执行时效果很好,因为它是有效的bash
命令。
使用 Perl sh
执行时无法正常工作,因为它不是有效的sh
命令。
如果要执行bash
命令,则需要实际执行bash
。
my $result = `bash -c bash_commmand_here`;
让我们解决一些插值问题。
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`