【发布时间】:2022-01-14 15:54:25
【问题描述】:
我有一个带有函数的 shell 脚本,当我调用该函数时,我收到了错误的数字错误。在我的函数中,我从数据库中获取一个文件名并返回它。返回给出“错误号码”错误。详情如下:
call to GET_MYFILE() :
GET_MYFILE $jobid
--$job id has the correct number in it
GET_MYFILE()
{
echo "job id input parameter is : " $1
curfile=`sqlplus -s /@username<< EOF
set feed off heading off verify off serveroutput off
select my_file_name
from my_table_name
where jobid=$1;
exit;
EOF`
echo "curfile is : " $curfile
return $curfile
}
-- echo "curfile is : " $curfile - displays correct filename
--return $curfile gives bad number error.
【问题讨论】:
-
return不能返回任意数据,只能返回整数退出状态。 Shell 函数确实不是很像函数。它们更像是小程序。 -
return到一个函数类似于exit到一个 shell 脚本。它设置状态($?)并返回给调用者。