[英]how to invoke unix inside perl
i am trying to execute following command 我正在尝试执行以下命令
#!/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";
But getting an error: 但是得到一个错误:
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `sepman -l|grep -e afs( | wc -l'
please help me how to invoke unix command inside perl script 请帮我如何在perl脚本中调用unix命令
If line 16 is a typo, instead of 如果第16行是拼写错误,而不是
$cmd= `sepman -l|grep -e $srv_name\( | wc -l`;
you should wrote 你应该写
$cmd= `sepman -l|grep -e "$srv_name" | wc -l`;
If it's not a typo, then write : 如果它不是拼写错误,那么写:
$cmd= `sepman -l|grep -e "$srv_name\(" | wc -l`;
"Double quote" every literal that contains spaces/metacharacters and every expansion: "$var"
, "$(command "$var")"
, "${array[@]}"
, "a & b"
. “双引号”每个包含空格/元字符和每个扩展的文字:
"$var"
, "$(command "$var")"
, "${array[@]}"
, "a & b"
。 Use 'single quotes'
for code or literal $'s: 'Costs $5 US'
, ssh host 'echo "$HOSTNAME"'
. 对代码或文字
$'s: 'Costs $5 US'
使用'single quotes'
$'s: 'Costs $5 US'
, ssh host 'echo "$HOSTNAME"'
。 See 看到
http://mywiki.wooledge.org/Quotes http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments http://mywiki.wooledge.org/Arguments
http://wiki.bash-hackers.org/syntax/words http://wiki.bash-hackers.org/syntax/words
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.