bobblebub
bobblebub

Reputation: 33

Syntax error near unexpected token `='()

I'm running some legacy code on bash shell and I'm having trouble understanding/passing through this line:

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

The error I get is:

line 364: syntax error near unexpected token `='() {  eval `/usr/bin/modulecmd bash $*`
}''
line 364: `}'; export BASH_FUNC_module()'

Any pointers would be appreciated, I'm new to shell :) Thanks!

Upvotes: 2

Views: 4383

Answers (3)

Friendly Fire
Friendly Fire

Reputation: 55

Mike Frysinger correctly describes the problem cause. However, solving the problem generally requires one of several steps:

  • Uninstall the offending package, usually named environment-modules,
  • Modify the legacy code to skip environment variables that begin w/"BASH_FUNC_",
  • Remove it from your environment before running the legacy code with: unset -f module

More generally, to unset all exported functions you could use the following:

unset -f $(env | awk '/^BASH_FUNC_/{sub("[(].*","");print substr($0,11)}')

Of course:

  • uninstalling the package will not alter the current shell.
  • the unset -f command also has the effect of removing the function(s) from the current shell.

Upvotes: 0

chepner
chepner

Reputation: 531235

You are incorrectly combining the syntax for assignment and function definitions.

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

Upvotes: 0

Mike Frysinger
Mike Frysinger

Reputation: 3072

it looks like you're trying to convert some trace/dump output of bash. most likely you want:

module() { eval `/usr/bin/modulecmd bash $*`; }
export -f module

that should work on old/new versions of bash.

Upvotes: 2

Related Questions