3 ms·
SCRIPT_DIR="$(dirname $0)"
It also works when you're not running bash.
SCRIPT_DIR="$(dirname $0)"
It also works when you're not running bash.
This doesn't work if $0 contains whitespace. Fix it by using "$0" instead.
That's essentially what he did, but he also accounted for the case of running a script from the current directory by running pwd.