How to define a bash function for use in any script?

While I basically agree with @eduffy, I typically put such functions in a file either in the user's home directory or if the scripts are shared between users in a directory in the user's path. I would then source the file (. ~/FILE or . $(type -p FILE)) in the .bash_profile. This allows you to 're-source' the file if necessary (i.e., you change something in it) w/o having to re-login, etc.


In bash, you can run source from your script (with the file containing your functions as the argument) and simply call the function. This is what happens implicitly when you define the function in your .bashrc file.