Created
May 14, 2012 02:53
-
-
Save nicerobot/2691519 to your computer and use it in GitHub Desktop.
Canonicalize a file's path i.e. a cross platform readlink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# eg. dir=$(canonical $0) | |
canonical() { | |
local d="$(\dirname ${1})" | |
local f="$(\basename ${1})" | |
( | |
\cd ${d} >/dev/null 2>&1 | |
while [ -h "${f}" ] ; do | |
\cd $(\dirname $(\readlink ${f})) >/dev/null 2>&1 | |
done | |
\pwd -P | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just curious what's the diff between
and
also curious why you are using
${1}
instead of
${0}
?