Can a bash function be used in different scripts?

Sure – in your script, where you want to use the function, you can write a command like

source function.sh

which is equivalent to including the contents of function.sh in the file at the point where the command is run. Note that function.sh needs to be in one of the directories in $PATH; if it’s not, you need to specify an absolute path.

Leave a Comment