Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have to determine the directory of a script which is symlinked.

/usr/local/src/myscript/myscript.sh
/usr/local/bin/myscript.sh (Symlink to the one above)

A cronjob executes /usr/local/bin/myscript.sh. Inside myscript.sh I am trying to determine where the original location is (which is /usr/local/src/myscript/ in this case). How to do that?

share|improve this question

1 Answer 1

The solution is

$( cd "$( dirname "`readlink ${BASH_SOURCE[0]}`" )" && pwd )
share|improve this answer
    
I'd even go for readlink -f to canonicalize even further. –  Dennis Kaarsemaker Nov 21 '12 at 20:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.