I like writing shell scripts, but one thing that has bugged me for years is that I don't reliably know how to include relative scripts. I run into three key problems:
Use
full article
. relative/script.sh
depends on the invocation dir.- Symlinking the command results in inconsistent command name and location.
- Almost all internet discussion about shell scripting is about Bash, whereas I'm using sh(1) on FreeBSD (aka Bourne shell).
Use
$(dirname $(realpath $0))
in your command files. realpath(1)full article