我正在写一个函数
func-def.sh:
function func() {
# assign _f_desc here ....
}
run-main.sh :
function call_all_func() {
source func-def.sh
# when I call the function from here
_f_desc=
func _f_desc
# here I must get the function description of the function
# that was last executed ...
}
简而言之,我希望将_f_desc
传递给func()
并期望func()
填写描述其用法的短字符串..例如。 _f_desc
可能包含"This function multiplies 2 nos"
答案 0 :(得分:0)
您不需要显式传递变量以便能够更改它。见下面的脚本:
function call_all_func() {
local _f_desc
func
echo "$_f_desc"
}
function func() {
_f_desc="This function multiplies 2 nos"
}
现在打电话:
call_all_func
它将打印:
This function multiplies 2 nos