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'

2 Answers 2

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

3
  • Note that in bash, a hyphen is allowed in a function name, just not in a parameter name.
    – chepner
    Commented Sep 26, 2014 at 1:53
  • @chepner What about an underscore? Is an underscore allowed in a function name and parameter name?
    – Josh Pinto
    Commented May 18, 2016 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
    Commented Jun 8, 2016 at 7: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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .