What is the best way to include other scripts?

Posted by Aaron H. on Stack Overflow See other posts from Stack Overflow or by Aaron H.
Published on 2008-10-10T17:14:38Z Indexed on 2014/05/31 9:27 UTC
Read the original article Hit count: 169

Filed under:

The way you would normally include a script in bash is source. For example:

main

#!/bin/bash

source incl.bash

echo "The main script"

incl.bash

echo "The included script"

The output of executing ./main:

The included script
The main script

Now, if you attempt to execute that shell script from another location, it can't find the include unless it's in your PATH.

What's a good way to ensure that your script can find the included script, especially if for instance, the script needs to be portable?

© Stack Overflow or respective owner

Related posts about bash