If I don't want to alter my PATH envariable, then it makes sense to symbolic link the jmeter startup script to someplace already in my PATH. But `dirname $0` finds the symbol's location. Here is a fixed script (tested linux, solaris) #! /bin/sh #java -Xincgc -jar `dirname $0`/ApacheJMeter.jar "$@" truedirname() { if test -L $0 ; then x=`/bin/ls -l $0` for i in $x ; do : done case "$i" in /*) x=`dirname $i` ;; *) x=`dirname $0`/`dirname $i` ;; esac else msg="$msgd" x=`dirname $0` fi here=`pwd` cd $x 2>&1 > /dev/null pwd cd $here 2>&1 > /dev/null } java -Xincgc -jar `truedirname $0`/ApacheJMeter.jar "$@" I don't claim this is elegant... but it works for me.
(In reply to comment #0) > If I don't want to alter my PATH envariable, then it makes sense to symbolic > link the jmeter startup script to someplace already in my PATH. But `dirname $0` > finds the symbol's location. Here is a fixed script (tested linux, solaris) > > #! /bin/sh > #java -Xincgc -jar `dirname $0`/ApacheJMeter.jar "$@" > truedirname() { > if test -L $0 ; then > x=`/bin/ls -l $0` > for i in $x ; do > : > done > case "$i" in > /*) x=`dirname $i` ;; > *) x=`dirname $0`/`dirname $i` ;; > esac > else > msg="$msgd" > x=`dirname $0` > fi > here=`pwd` > cd $x 2>&1 > /dev/null > pwd > cd $here 2>&1 > /dev/null > } > > java -Xincgc -jar `truedirname $0`/ApacheJMeter.jar "$@" > > I don't claim this is elegant... but it works for me. A better way to do this is to use readlink like so: java -Xincgc -jar $(dirname $(readlink $0)) "$@" Readlink was originally a BSD utility, but I believe it exists in most, if not all, Linux distos. I haven't found one yet that doesn't have it... even some of our older RHEL3 servers have it. P.S. the backticks ` are deprecated in Bash now. The $( ) syntax is preferred instead.
*** Bug 55994 has been marked as a duplicate of this bug. ***
readlink works OK for absolute soft-links and relative soft-links in the current directory. However if a relative soft-link is accessed via the PATH, then the technique does not work; it will be necessary to convert the relative link to an absolute one. Looks like readlink -f does what is wanted; however does it exist on all Unix-like systems? If it does, then java $JVM_ARGS $JMETER_OPTS -jar `dirname $0`/ApacheJMeter.jar "$@" can simply be changed to java $JVM_ARGS $JMETER_OPTS -jar `dirname readlink -f $0`/ApacheJMeter.jar "$@" To allow for spaces in path names, one would need: java $JVM_ARGS $JMETER_OPTS -jar "`dirname readlink -f $0`/ApacheJMeter.jar" "$@" Is "readlink -f" supported on MacOS? Seems to work OK on FreeBSD and Ubuntu.
readlink is not available on Solaris. Here's a snippet from Tomcat bin/catalina.sh that is there since more than 7 years and seems to work reliably on many platforms (as we expect Tomcat to be used on almost any platform): ... # resolve links - $0 may be a softlink 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 # Get standard environment variables PRGDIR=`dirname "$PRG"` ... Regards, Rainer
(In reply to Rainer Jung from comment #4) > readlink is not available on Solaris. Useful to know. > Here's a snippet from Tomcat bin/catalina.sh that is there since more than 7 > years and seems to work reliably on many platforms (as we expect Tomcat to > be used on almost any platform): Excellent.
Fixed: URL: http://svn.apache.org/r1558834 Log: Unix jmeter start script assumes it is on PATH, not a link Bugzilla Id: 21695 Modified: jmeter/trunk/bin/jmeter.sh jmeter/trunk/xdocs/changes.xml Note that an additional change to the script was needed to allow for spaces in the JMeter installation path (perhaps should have been raised as a separate bug)
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/1173