Sunday, October 09, 2011

Making a bash script know its current directory location

I use the following variables at the beginning of my Bash script to get such information:

EXECUTED_FROM_DIR=`pwd`
THIS_SCRIPT_DIR=$(cd $(dirname "$0"); pwd)
cd $THIS_SCRIPT_DIR


#Do different tasks here
...


cd $EXECUTED_FROM_DIR

No comments: