What is the best way to include other scripts?
- by Aaron H.
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?