【发布时间】:2013-04-03 15:07:22
【问题描述】:
我有一个调用 perl 脚本的 shell 脚本。 shell 脚本是一个包装器,它构建要传递给 perl 脚本的参数。 perl 脚本使用给定的参数执行一些代码。
shell脚本是这样的。
#!/bin/bash
value=1
opt2value="someValue"
params="-opt3 someOption"
if [ $value = 1 ]
then
params=${params}" -opt4 Y -opt5 \"This is 1\""
elif [ $value = 2 ]
then
params=${params}" -opt4 Y -opt5 \"This is 2\""
else
params=${params}" -opt4 N"
fi
perl -E'say for 0+@ARGV, @ARGV;' -- -opt1 optValue -opt2 ${opt2value} ${params}
Perl 脚本检索所有其他传递的参数,但它只检索 opt5 参数的 "This,而不是传递的整个值。
用于检索值的 perlScript
use Getopt::Long;
$result = GetOptions(
"opt1=s" => \$opt1,
"opt2=s" => \$opt2,
"opt3=s" => \$opt3,
"opt4=s" => \$opt4,
"opt5=s" => \$opt5
}
我该怎么做。谢谢。
【问题讨论】:
-
然后呢???????????
-
代码是这样的。
-
对不起。太早点击保存按钮
-
你确定整个
" -option2 Y -option3 \"This is 2\""都被传递给 perl 脚本了吗? -
@Miguel Prz,对于初学者来说,Perl 脚本无法区分
script ... "This is 2"和script ... This is 2
标签: bash shell command-line-arguments