I'm trying to maintain some bash scripts to be used across a few different platforms. I've hit something weird with exporting functions I can't explain. The following test script:

function test_fn() {                                                                   
    echo "In test_fn()"
export -f test_fn                                                             
echo test1 test2 |  xargs -d ' ' -n1 -I{} bash -c "test_fn {}" 

Behaves differently in bash 4.1 and 4.3, and I'm not sure why:

$ /bin/bash test-fn.sh
bash: test_fn: command not found
$ /bin/bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
$ bash test-fn.sh
In test_fn()
In test_fn()
$ bash --version
GNU bash, version 4.3.39(1)-release (x86_64-unknown-linux-gnu)

Is this perhaps some sort of effect of the shellshock fixes?

  • Works for me in 4.1.2(1) (redhat) and 4.3.42(4) (cygwin). – choroba Nov 13 '15 at 17:31
  • Worked for me in 4.1.5(1)-release (x86_64-pc-linux-gnu) (Debian squeeze), 4.3.42(1)-release (x86_64-unknown-linux-gnu) (Arch, latest non-testing). – muru Nov 13 '15 at 17:45

Your Answer

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

Browse other questions tagged or ask your own question.