Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将值从Perl程序返回到KornShell脚本?_Perl_Unix_Shell_Ksh - Fatal编程技术网

如何将值从Perl程序返回到KornShell脚本?

如何将值从Perl程序返回到KornShell脚本?,perl,unix,shell,ksh,Perl,Unix,Shell,Ksh,我想在shell脚本中执行此操作: #!/usr/bin/ksh PERL_PATH=/usr/local/bin/perl RET1=$(${PERL_PATH} missing_months_wrap.pl) echo $RET1 我该怎么做 如上所述调用perl脚本给了我一个错误: > shell.sh Can't return outside a subroutine at missing_months_wrap.pl line 269. EDIT:perl脚本中的语句是

我想在shell脚本中执行此操作:

#!/usr/bin/ksh

PERL_PATH=/usr/local/bin/perl

RET1=$(${PERL_PATH} missing_months_wrap.pl)

echo $RET1
我该怎么做

如上所述调用perl脚本给了我一个错误:

> shell.sh
Can't return outside a subroutine at missing_months_wrap.pl line 269.
EDIT:perl脚本中的语句是:

unless (@pm1_CS_missing_months)
{
$SETFLAG=1;
}

my @tmp_field_validation = `sqlplus -s $connstr \@DLfields_validation.sql`;

unless (@tmp_field_validation)
{
$SETFLAG=1;
}

if ($SETFLAG==1)
{
return $SETFLAG;
}

您需要修改Perl脚本,以便它输出您需要的值(到stdout),然后您可以在shell脚本中使用该值。

shell脚本可以从$中的Perl脚本检索退出状态?变量或Perl脚本的输出(如果使用backticks或subshell调用)

perl test.pl
VAR=$?
一定要拿到美元?值,因为它可能会更改

VAR=`perl test.pl`
或 VAR=$(perl test.pl)


对于第二种方法,变量可以是字符串,而对于第一种方法,变量必须是介于0和255之间的整数值

shell脚本中对
RET1
的赋值运行Perl命令并捕获其标准输出。要使Perl程序继续运行,请将末尾的条件更改为

if ($SETFLAG==1)
{
  print $SETFLAG;
}
运行它会产生

1 并将
missing_months_wrap.pl
中的最后一个条件更改为

if ($SETFLAG==1)
{
  exit $SETFLAG;
}
您将获得相同的输出:

$ PERL_PATH=/usr/bin/perl ./shell.sh 1 $PERL_PATH=/usr/bin/PERL./shell.sh
1
perl test.pl
返回什么?输出是否打印到屏幕上?它必须是介于0和255之间的整数值。另外,不要使用反勾号-
$()
更适合于可读性、嵌套性和易于引用和转义。 $ PERL_PATH=/usr/bin/perl ./shell.sh 1