Creating Function Libraries
For a convenient way to make your functions reusable, just place them into a function library. Then, from within your scripts, call the desired libraries with either a source
command or a dot command. If you’re the only one who will ever use the libraries, you can place them in your own home directory.
If you want to make them available for everyone, you can place them in a central location, such as in the /usr/local/lib/
directory.
For a simple demonstration, I’ve created the donnie_library
file in the /usr/local/lib/
directory with two simple functions. It looks like this:
howdy_world() {
echo "Howdy, world!"
echo "How's it going?"
}
howdy_georgia() {
echo "Howdy, Georgia!"
echo "How's it going?"
}
(I live in the state of Georgia, which explains the second function.)
There’s no need to set the executable permission on this file, because it only contains code that...