Strange bash error: “error importing function definition for `BASH_FUNC_module'”

Posted on

Problem :

Sample script:

#!/usr/bin/env bash
echo "abc"

Output from Bash version 4.1.2(1)-release:

$ ./a.bash
bash: BASH_FUNC_module(): line 0: syntax error near unexpected token `)'
bash: BASH_FUNC_module(): line 0: `BASH_FUNC_module() () {  eval `/usr/bin/modulecmd bash $*`'
bash: error importing function definition for `BASH_FUNC_module'

Output from Bash version 3.2.25(1)-release:

$ ./a.bash

Interestingly, they both work, but I would like to remove that ugly message.

I think this is related to the Shellshock patch, but I need some help to confirm.

I did some Googling, and most pages point to behaviour of Bash after Shellshock patching, but I don’t know the correct workaround.

What is the workaround for this issue?

I am working at a “mega corp”, so control over installed packages is nil.

Solution :

The only immediately obvious error is that someone did eval `/usr/bin/modulecmd bash $*`. There are too many weird things in that code to go into detail (does it really need eval, why the ye olde style backticks, why $* instead of $@, and why are there no quotes anywhere), but it looks like you may have a severely handicapped shell to deal with.

I was having this same problem since I began using “Environment Modules”. The solution (for me at least) was to update bash
I had been using bash 4.1.2-15.el6 and updated to bash 4.1.2-29.el6 with:
yum update bash
Obviously you may not be able to convince “mega corp” to update but given the concern around shellshock they might listen to you?