1

I have a script file, let's say abc.sh. The full path is /home/path/to/script/abc.sh. Now I am currently executing the script from /path/to/current by executing this command -
sh /home/path/to/script/abc.sh. I want this script to echo it's location. The output should be /home/path/to/script

bosari
  • 1,922
  • 1
  • 19
  • 38

1 Answers1

2

Use this script.

#!/bin/bash
current_location=$(pwd)
script_location=$(dirname $0)
if [ $script_location= '.' ]
then
 script_location="$current_location"
fi
echo $script_location
Vishnu T S
  • 3,476
  • 2
  • 23
  • 39