Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Try a new technique for finding jruby home that avoids 'expr'.

  • Loading branch information...
commit b1fec0dd242ee473094cbba32dc7a553f24dbb0b 1 parent d72d2b7
@headius headius authored
Showing with 14 additions and 16 deletions.
  1. +14 −16 bin/jruby.bash
View
30 bin/jruby.bash 100644 → 100755
@@ -25,24 +25,22 @@ if [ -z "$JAVA_VM" ]; then
JAVA_VM=-client
fi
-## resolve links - $0 may be a link to home
-PRG=$0
-progname=`basename "$0"`
-
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '.*/.*' > /dev/null; then
- if expr "$link" : '/' > /dev/null; then
- PRG="$link"
- else
- PRG="`dirname ${PRG}`/${link}"
- fi
- else
- PRG="`dirname $PRG`/$link"
- fi
+# get the absolute path of the executable
+SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && SELF_PATH=$SELF_PATH/$(basename -- "$0")
+
+# resolve symlinks
+while [ -h $SELF_PATH ]; do
+ # 1) cd to directory of the symlink
+ # 2) cd to the directory of where the symlink points
+ # 3) get the pwd
+ # 4) append the basename
+ DIR=$(dirname -- "$SELF_PATH")
+ SYM=$(readlink $SELF_PATH)
+ SELF_PATH=$(cd $DIR && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
done
+PRG=$SELF_PATH
+
JRUBY_HOME_1=`dirname "$PRG"` # the ./bin dir
if [ "$JRUBY_HOME_1" = '.' ] ; then
cwd=`pwd`
Please sign in to comment.
Something went wrong with that request. Please try again.