我有一个在 perl 中执行的 bash 命令,如下所示
@args = ( "bash" , "-c", "diff <(ssh -o \"StrictHostKeyChecking no\" user-db01 'mysql -uuser -ppass --execute=\"show databases\"') <(ssh -o \"StrictHostKeyChecking no\" user-db02 'mysql -uuser -ppass --execute=\"show databases\"')");
system(@args);
但这不允许我将输出获取到字符串变量。如果我用反引号执行完全相同的操作
$cmd = "bash -c diff <(ssh -o \"StrictHostKeyChecking no\" user-db01 'mysql -uuser -ppass --execute=\"show databases\"') <(ssh -o \"StrictHostKeyChecking no\" user-db02 'mysql -uuser -ppass --execute=\"show databases\"')";
my $res = `$cmd`;
它抛出一个错误sh: -c: line 0: syntax error near unexpected token
('`我该怎么做才能执行命令并在变量中获取结果?