get absolute path of a script

if you need the absolute path of the script you are running at the moment:

absPath=`echo -n \`pwd\` ;( [ \`dirname \$0\` == '.' ] && echo ) || echo "/\`dirname \$0\`"`

for example useful to build up libary paths in project folders.

2 Responses to “get absolute path of a script”

  1. Magnus Says:

    If you need a command which handles ../ etc you can use

    absPath=”$(cd $(dirname ${0}); pwd)”
    execName=”${absPath}/$(basename ${0})”

    Regards

    Magnus

  2. 666hellrid3r Says:

    thanks, looks much better than the version i found above..

Leave a Reply