这是我在cgi perl脚本中的foreach循环。 cgi正确排除,打印出每个变量,但只执行sed / sort系统命令一次。
如果我运行以下命令,我生成下面的html页面,数组大小为3,但只生成tmpsort1.txt。所有输入都已经过检查和验证。
foreach $path (@paths){
$i++;
print "$path\t";
$command = "sed 's/ (.*)//' $path | sort -k1 >/var/www/analyses/tmp/tmpsort$i.txt";
print "$command\t";
system("$command");
print "$path<br>";
}
输入路径---系统命令---重新检查输入路径
printed variables into the html page:
/var/www/analyses/abun/100_genus_proportion sed 's/ (.*)//' /var/www/analyses/abun/100_genus_proportion | sort -k1 >/var/www/tmp/tmpsort1.txt /var/www/analyses/abun/100_genus_proportion
/var/www/analyses/abun/113_genus_proportion sed 's/ (.*)//' /var/www/analyses/abun/113_genus_proportion | sort -k1 >/var/www/tmp/tmpsort2.txt /var/www/analyses/abun/113_genus_proportion
/var/www/analyses/abun/55_genus_proportion sed 's/ (.*)//' /var/www/analyses/abun/55_genus_proportion | sort -k1 >/var/www/tmp/tmpsort3.txt /var/www/analyses/abun/55_genus_proportion
只是为了确认,只创建了/var/www/tmp/tmpsort1.txt。运行脚本后其他的不存在。所有权限都是正确的。
编辑:只是要添加,我已尝试将sed和sort命令分离为单独的调用,我得到相同的结果。