Ma99uS Ma99uS - 1 year ago 100
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 ;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download