巴什 - 如何调用父外壳声明的函数? [英] Bash - How to call a function declared in a parent shell?

查看:69
本文介绍了巴什 - 如何调用父外壳声明的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写调用父shell声明的函数一个bash脚本,但它不能正常工作。

I am writing a bash script that calls functions declared in the parent shell, but it doesn't work.

例如:

$ 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

正如你所看到的剧本 ./ test.sh 无法调用函数 MYFUNC ,有一些方法,使该函数可见的脚本?

As you can see the script ./test.sh is unable to call the function myfunc, is there some way to make that function visible to the script?

推荐答案

尝试

$ export -f myfunc

在父外壳,出口的功能。

这篇关于巴什 - 如何调用父外壳声明的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆