I always did:
SCRIPT_PATH=$(cd `dirname ${0}`; pwd)
I have never used readlink before: is it just Gnu? (i.e. will it work with HP-UX, AIX and Solaris from the window? dirname and pwd will be ...)
(edited to add `` which I forgot in the original post. d'oh!) (edit 2 to put two lines, which I apparently always did when I looked at the previous scripts that I wrote, but not remembered correctly. The first call gets the path, the second call excludes the relative path) (edit 3 fixed typos that prevent one line answer from working, back to one line!)
source share