I came across a bash_profile file that makes use of the export -f statement in the following manner:

# Run xelatex and BibTeX
function xelatex_bibtex {
    xelatex -shell-escape "${1}.tex" &&
        bibtex "${1}" &&
        xelatex -shell-escape "${1}.tex" &&
        xelatex -shell-escape "${1}.tex"
export -f xelatex_bibtex

However, functions defined without export -f seem to work perfectly fine:

# Search for synonyms
function syn {
    wn "${1}" -synsn

What's the role of export -f and what's considered good practice when creating convenience function in bash_profile with respect to using export?


Its role is exactly analogous to that in the case of variables - i.e. to export the definition to inherited environments.


$ foo() { echo bar; }
$ foo

Start a child shell

$ bash


$ foo

Command 'foo' not found, did you mean:

  command 'roo' from snap roo (2.0.3)
  command 'fio' from deb fio
  command 'fgo' from deb fgo
  command 'fog' from deb ruby-fog
  command 'woo' from deb python-woo
  command 'fox' from deb objcryst-fox
  command 'goo' from deb goo
  command 'fop' from deb fop

See 'snap info <snapname>' for additional versions.

whereas the same child shell after exporting the function:

$ export -f foo
$ bash
$ foo

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.