我正在尝试执行以下命令
#!/usr/bin/perl
$num_args = $#ARGV + 1;
if ($num_args != 1) {
print "\nUsage: name.pl srv_name \n";
exit;
}
$srv_name=$ARGV[0];
#$last_name=$ARGV[1];
if( $srv_name eq "afs" || $srv_name eq "mnp") {
print "You have entred Service Name=$srv_name\n";
}
$cmd= `sepman -l|grep -e $srv_name\( | wc -l`;
print "cmd= $cmd\n";
但是出现错误:
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `sepman -l|grep -e afs( | wc -l'
请帮助我如何在 perl 脚本中调用 unix 命令
最佳答案
如果第 16 行是一个错字,而不是
$cmd= `sepman -l|grep -e $srv_name\( | wc -l`;
你应该写
$cmd= `sepman -l|grep -e "$srv_name" | wc -l`;
如果不是打字错误,那么写:
$cmd= `sepman -l|grep -e "$srv_name\(" | wc -l`;
“双引号”每个包含空格/元字符和每个扩展的文字:"$var"
, "$(command "$var")"
,“${array[@]}”
,“a & b”
。使用 'single quotes'
作为代码或文字 $'s: 'Costs $5 US'
, ssh host 'echo "$HOSTNAME"'
。见
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments
http://wiki.bash-hackers.org/syntax/words
关于perl - 如何在 perl 中调用 unix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27817659/