When I run sh ./mypath/myscript.sh
with the code below,
BASEDIR=$(dirname "$0")
echo "$BASEDIR"
I got ./mypath
which is great.
However, since I need to source
due to -bash: [: =: unary operator expected. when no parameter given,
The above code doesn't work, but just return -bash
instead. Is there an equivalent of the above code that work when source
instead of sh
?