0

Have added a number of functions which I source from my .bashrc. For instance, I use

export -f calc

I also have another function usage_calc where I comment out the export call

# export -f usage_calc

But I can still call usage_calc. What is happening?

Vera
  • 1,173
  • 4
  • 17
  • 1
    You have a executable, alias or shell function called `myfunc2` which calls `myfunc`. Without more information there is nothing more anyone can tell you. – Kusalananda Nov 27 '21 at 09:29
  • 1
    Does this answer your question? [Role of export -f statement when creating functions in bash\_profile](https://unix.stackexchange.com/questions/463344/role-of-export-f-statement-when-creating-functions-in-bash-profile) – rowboat Nov 27 '21 at 09:50
  • It does not really address the requirements of `export` though. – Vera Nov 27 '21 at 17:07

1 Answers1

1

You're using bash as your shell. The function is defined in or via your .bashrc, which makes the function available to your shell. The export has no relevance

roaima
  • 107,089
  • 14
  • 139
  • 261
  • Eons I go, I had to include `export -f` so that function names are recognised as functions. Now I am clueless on when I need to call export and when there is no need for it. – Vera Nov 27 '21 at 17:09
  • @Aardvark for functions (and variables generally), don't use `export` unless you've a specific requirement – roaima Nov 27 '21 at 17:10
  • Could you list me a few instances when `export` is needed. I think I need to use export on some functions. – Vera Nov 27 '21 at 17:20
  • If you want to use a function in a bash shell that does not first call .bashrc – roaima Nov 27 '21 at 17:38
  • And now it hit me. If you define a shell function in your .bashrc file, it will not be available to scripts, only to your interactive shell. Is there some good practice for this? – Vera Nov 27 '21 at 18:11
  • @Aardvark yes. Don't have your scripts assume too much about the environment. If I'm writing for a multiuser system I can't assume that someone's got my functions defined in their `.bashrc` – roaima Nov 27 '21 at 18:34
  • Not assuming the functions are defined in the .bashrc requires sourcing the file dependencies before using the functionalities defined in them. This means that generally speaking, one does not export function names, but one may export specific variables for the software packages that need them. – Vera Nov 27 '21 at 18:51