Given an absolute or relative path (in a Unix-like system), I would like to determine the full path of the target after resolving any intermediate symlinks. Bonus points for
Try this:
cd $(dirname $([ -L $0 ] && readlink -f $0 || echo $0))