this is something that I searched for quite some time and could not find yet, maybe a helpful soul knows.
In a bourne shell script, how can I find the full path of the script being executed?
Thanks in advance.
Update: the following command, sent by Celso Pinto, passes all my tests.
cd $(dirname $0);pwd
For the record, I used two scripts to test this. First, the
echo "\$0 is $0" SCRIPTDIR=
dirname $0echo " dir: $SCRIPTDIR" SCRIPTDIR="
cd $(dirname $0);pwd" echo " dir: $SCRIPTDIR"
The script to run the tests,
chmod 755 script_dir.sh
./script_dir.sh 1 ../$USER/script_dir.sh 2 ../$USER/bin/../script_dir.sh 3
sh ./script_dir.sh 1 with sh sh ../$USER/script_dir.sh 2 with sh sh ../$USEr/bin/../script_dir.sh 3 with sh
cd / script_dir.sh "via path"