Tue 19 Jun 2007
Shell : Find out the full path to executed script
Posted by admin under linux , programming , shellNo Comments
Was looking around to find a simple method to find the fullpath or explicit path for the script running.
After a while of searching I found this useful simple snippet: bash, full filename.
And used it like this in the beginning of the script:
PRG="$0"
OLDPWD=`pwd`
B=`basename $PRG`
P=`dirname $PRG`
# echo BASE:$B PATH:$P
cd $P
if [ `pwd` != "/" ]
then
FULLNAME=`pwd`/$B
else
FULLNAME=/$B
fi
echo $FULLNAME
cd $OLDPWD
echo `pwd`
… simple but effectiv.