In a bash script I'm writing, I use
They recommend avoiding the very commonly used
Nothing that reads
$0will ever be bulletproof, because
$0itself is unreliable.
They suggest you use
$BASH_SOURCE instead. Something like this:
I recommend you check out the page, as they suggest other options as well. They also recommend
cd in combination with
$BASH_SOURCE in cases where it will work for you.