Rory Rory - 7 months ago 29
Bash Question

Bash - How to call a function declared in a parent shell?

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

For example:

$ function myfunc() { echo "Here in myfunc" ; }
$ myfunc
Here in myfunc
$ cat
#! /bin/bash

echo "Here in the script"
$ ./
Here in the script
./ line 4: myfunc: command not found
$ myfunc
Here in myfunc

As you can see the script
is unable to call the function
, is there some way to make that function visible to the script?



$ export -f myfunc

in the parent shell, to export the function.