15

I encountered this error when updating bash for the CVE-2014-6271 security issue:

# yum update bash
Running transaction (shutdown inhibited)
Updating   : bash-4.2.47-4.fc20.x86_64
/bin/sh: error importing function definition for `some-function'
D McKeon
  • 766
  • 6
  • 15

2 Answers2

18

[edited after 1st comment from: @chepner - thanks!]

/bin/bash allows hyphens in function names, /bin/sh (Bourne shell) does not. Here, the offending "some-function" had been exported by bash, and bash called yum which called /bin/sh which reported the error above.

fix: rename shell functions to not have hyphens

man bash says that bash identifiers may consist: "only of alphanumeric characters and underscores"

The /bin/sh error is much more explicit:

some-function () { :; }

sh: `some-function': not a valid identifier

D McKeon
  • 766
  • 6
  • 15
  • Note that in `bash`, a hyphen is allowed in a function name, just not in a parameter name. – chepner Sep 26 '14 at 01:53
  • @chepner What about an underscore? Is an underscore allowed in a function name and parameter name? – Josh Pinto May 18 '16 at 10:38
  • On my system bash 4 allows function names to have hyphens *but* bash 3 does not — I assume on the OP's system /bin/sh is bash 3, and /bin/bash is bash 4 – Mark Fox Jun 08 '16 at 07:08
2

Change/Fix the function name from "foo-bar" to "foo_bar"

It is the naming convention that bash is ok with, where as sh is not.

Replace the "-"(hyphen/dash/minus) with "_"(underscore), and the error gets fixed, and the code works on both bash and sh

Sun
  • 181
  • 4