Ma99uS Ma99uS - 11 months ago 45
Linux Question

How to get script file path inside script itself when called through sym link

When I need to get path to the script file inside script itself I use something like this:

`dirname $0`

that works file until I call the script through sym link to it. In that case above code prints the location of the link instead the original file.

Is there a way to get the path of the original script file, not the link?


dsm dsm
Answer Source
if [ -L $0 ] ; then
    DIR=$(dirname $(readlink -f $0)) ;
    DIR=$(dirname $0) ;
fi ;