将函数调用传递给子 shell

问题描述 投票:0回答:1

我的 ksh

main_script
调用了另一个脚本
called_script
called_script
最终创建了一个子 shell,我想继续在其中工作。我向它传递了一个需要执行的函数
fun

called_script <<< '
fun
'

我得到一个错误说

fun: not found [No such file or directory]
,但是当我运行
called_script
然后手动运行
fun
(即直接不使用
main_script
)时它有效。在我看来,
called_script
执行定义了函数。在那种情况下,为什么使用
main_script
最终会得到不同的结果?

注意:我不能改变

called_script
.

编辑:我相信

called_script
生成一个 shell 并调用其他定义
fun
的脚本。在运行我在
called_script
的此处字符串中传递的内容之前,我需要
main_script
完全完成它。有什么办法控制顺序吗

bash shell ksh
1个回答
0
投票

子进程中定义的任何函数将无法用于

main_script
,除非您将其导出:

called_script <<< '
export -f fun
fun
'
© www.soinside.com 2019 - 2024. All rights reserved.