In a script I get in $0 the possible relative path to it. For converting it to absolute I've found this solution which I don't understand:
abspath=$(cd ${0%/*} && echo $PWD/${0##*/})
My problem is the magic inside of ${0%/*} and ${0##*/}. It looks like the former extracts the dirname and the latter extracts the filename, I just don't get how.


readlink -f $0to get the canonical path. – Shawn J. Goff Mar 18 '11 at 13:22dirnameutil is useful here. – D4RIO Mar 18 '11 at 14:09