我正在编写一个调用父shell中声明的函数的bash脚本,但它不起作用.
例如:
$ function myfunc() { echo "Here in myfunc" ; }
$ myfunc
Here in myfunc
$ cat test.sh
#! /bin/bash
echo "Here in the script"
myfunc
$ ./test.sh
Here in the script
./test.sh: line 4: myfunc: command not found
$ myfunc
Here in myfunc
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,脚本./test.sh
无法调用该函数myfunc
,是否有某种方法可以使该函数对脚本可见?
unw*_*ind 26
尝试
$ export -f myfunc
Run Code Online (Sandbox Code Playgroud)
在父shell中,导出该函数.