Reputation: 151
In bash, we can export a function in the following way:
fname(){
echo "Foo"
}
export -f fname
In this case, function fname
is exported. But how to list this or other exported functions? AFAIK, command export
or export -p
can be used for displaying all the exported/included variables but this does not including functions.
Upvotes: 4
Views: 3141
Reputation: 313
The output of the chosen solution is:
declare -fx exported_function_one declare -fx exported_function_two
In my case, as I just wanted the name of the functions, I did this:
exported_functions=$(declare -x -F | sed 's/declare -fx//')
Which outputs:
exported_function_one exported_function_two
Hope it helped someone :D
Upvotes: 0
Reputation: 4658
declare
is the command to use.
Here's an example of setting and exporting some functions and listing them all, or just a specific one:
$ foo() { echo "Foo"; }
$ export -f foo
$ bar() { echo "Bar"; }
$ export -f bar
$
$ declare -f
bar ()
{
echo "Bar"
}
declare -fx bar
foo ()
{
echo "Foo"
}
declare -fx foo
$
$ declare -f foo
foo ()
{
echo "Foo"
}
$
Upvotes: 0
Reputation: 1169
The following will list all exported functions by name:
declare -x -F
If you want also see the function code use:
declare -x -f
See help declare
for details.
Upvotes: 8