Permalink
Browse files

Added recursive canonical readlink function to cater to symlink depth…

… greater than 1 on FreeBSD/OS X
  • Loading branch information...
1 parent 28ee6df commit e37cd73e0f9bee15cc046de099673c8234fa9d33 Nicholas Robinson committed with dominictarr Oct 26, 2011
Showing with 18 additions and 2 deletions.
  1. +18 −2 bin/json_parse
View
@@ -1,6 +1,22 @@
#!/usr/bin/env bash
+# Define BSD-friendly canonicalized readlink
+canonical_readlink ()
+{
+ __filename=$1
+ cd `dirname $__filename`
+ __filename=`basename $__filename`
+ if [ -h "$__filename" ]
+ then
+ echo $__filename
+ canonical_readlink `readlink $__filename`
+ else
+ __dirname=`pwd -P`
+ echo "$__dirname/$__filename"
+ fi
+}
+
#add this feature to require...
-__filename=$(cd "$(dirname "$0")"; pwd)
-. $__filename/../parse.sh
+__filename=$(canonical_readlink $0)
+. `dirname $__filename`/../parse.sh
tokenize | parse

0 comments on commit e37cd73

Please sign in to comment.