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'

[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

  • Note that in bash, a hyphen is allowed in a function name, just not in a parameter name. – chepner Sep 26 '14 at 1:53
  • @chepner What about an underscore? Is an underscore allowed in a function name and parameter name? – BH2017 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 8 '16 at 7:08

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.