How can I find full path of the original file being executed when user executes file not directly but through a softlink. To be more precise, assume I have /original/path/a.sh, and a softlink to that file here: ~/Desktop/link-to-a.sh. How can I find "/original/path/" inside a.sh if user actually executes ~/Desktop/link-to-a.sh?
The following variable holds ~/Desktop/ which is not useful.
DIR="$( cd "$( dirname "$0" )" && pwd )"
Use
readlink.To get the real path to a soft linked directory containing your script :
If your soft link points directly to the script, not its directory, do this to get the real directory in which the script is contained :