What is the correct way to export a bash function after the shellshock updates?

209 Views Asked by At

I am having problems with a script currently, but I'm not sure of the correct syntax. I think the script was broken with the shellshock patch to bash, but I just want to check.

What is the correct way to export a bash function since the shellshock patch. And what was the correct way before the patch?

Here are a few examples of what I am looking for.

A.

export BASH_FUNC_module()='() {  eval `/usr/bin/modulecmd bash $*`\0012}'

B

export BASH_FUNC_module='() {  eval `/usr/bin/modulecmd bash $*`\0012}'

C

BASH_FUNC_module='() {  eval `/usr/bin/modulecmd bash $*`\0012}'
export -f BASH_FUNC_module
1

There are 1 best solutions below

0
John Kugelman On

The correct way to export a function hasn't changed. Define the function, then use export -f.

func() {
    foo
    bar
}
export -f func