How to Include Another bash Script in your Own bash Script

in «tip» by Michael Beard
Tags: , , , , ,

In the Include Files in Bash article, it gives some good examples (i.e. one reason to do this is for data, so it doesn't clutter up your script -- not stated, but I would use it this way).

Basically, it amounts to the following:

#!/usr/bin/env bash

source other-file.sh

or, to make sure that you can "reach" the file:

source $(dirname "$0")/other-file.sh

assumming that other-file.sh is in the same directory as the script that is running! Otherwise, you will probably need to include the whole path to it then. From How to include file in a bash shell script.

I had tried it, but then couldn't get it to work, which makes sense now.

I replaced their shebang with my preferred one, but other than that ... Seems simple enough, but I usually forget how to do it.