Rory Rory - 1 year ago 114
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?

Answer Source


$ export -f myfunc

in the parent shell, to export the function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download