my.sh
在里面,将使用param1和param2调用func_name().
我想创建一个帮助函数,只列出所有可用的函数,即使没有参数.
问题:如何从脚本内部获取脚本中所有函数名称的列表?
我想避免解析它并寻找功能模式.太容易出错了.
更新:代码.想要我的help()函数就像main() – 添加到代码中的函数会自动添加到帮助中.
#!/bin/sh
# must work with "set -e"
foo ()
{
echo foo: -$1-$2-$3-
return 0
}
# only runs if there are parameters
# exits
main ()
{
local cmd="$1"
shift
local rc=0
$cmd "$@" || rc=$?
exit $rc
}
if [[ "$*" ]]
then
main "$@"
die "how did we get here?"
fi
本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/linux-huoqushelljiaobenzhongdehanshumingliebiao.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:9 月 24, 2019 at 01:23 上午