Skip to content

Instantly share code, notes, and snippets.

@loverdos
Created October 1, 2010 09:52
Show Gist options
  • Save loverdos/606001 to your computer and use it in GitHub Desktop.
Save loverdos/606001 to your computer and use it in GitHub Desktop.
# program may be a soft-link
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
DIRNAME=`dirname "$PRG"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment