How are you running your script?
Here is a sample I cobbled together from the cited post:
#!/bin/bash
BASEDIR=$(dirname $0)
echo BASEDIR=$BASEDIR
echo dollar zero=$0
echo "The script you are running has basename `basename $0`, dirname `dirname $0`"
echo "The present working directory is `pwd`"
qsh
bash_script
BASEDIR=/home/buck
dollar zero=/home/buck/bash_script
The script you are running has basename bash_script, dirname /home/buck
The present working directory is /home/buck
./bash_script
BASEDIR=.
dollar zero=./bash_script
The script you are running has basename bash_script, dirname .
The present working directory is /home/buck
cd /
/home/buck/bash_script
BASEDIR=/home/buck
dollar zero=/home/buck/bash_script
The script you are running has basename bash_script, dirname /home/buck
The present working directory is /
cd /home/buck
/home/buck/bash_script
BASEDIR=/home/buck
dollar zero=/home/buck/bash_script
The script you are running has basename bash_script, dirname /home/buck
The present working directory is /home/buck
exit
qsh cmd(bash_script)
BASEDIR=/home/buck
dollar zero=/home/buck/bash_script
The script you are running has basename bash_script, dirname /home/buck
The present working directory is /home/buck
QSH CMD('/home/buck/bash_script')
BASEDIR=/home/buck
dollar zero=/home/buck/bash_script
The script you are running has basename bash_script, dirname /home/buck
The present working directory is home/buck
QSH CMD('./bash_script')
BASEDIR=.
dollar zero=./bash_script
The script you are running has basename bash_script, dirname .
The present working directory is /home/buck