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?

3
  • 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. Commented Nov 27, 2021 at 9:29
  • 1
    Does this answer your question? Role of export -f statement when creating functions in bash_profile Commented Nov 27, 2021 at 9:50
  • It does not really address the requirements of export though. Commented Nov 27, 2021 at 17:07

1 Answer 1

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

7
  • 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. Commented Nov 27, 2021 at 17:09
  • @Aardvark for functions (and variables generally), don't use export unless you've a specific requirement Commented Nov 27, 2021 at 17:10
  • Could you list me a few instances when export is needed. I think I need to use export on some functions. Commented Nov 27, 2021 at 17:20
  • If you want to use a function in a bash shell that does not first call .bashrc Commented Nov 27, 2021 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? Commented Nov 27, 2021 at 18:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.