diff --git a/src/tophat2.sh b/src/tophat2.sh index 4ab88ee6..a88a8d90 100644 --- a/src/tophat2.sh +++ b/src/tophat2.sh @@ -1,10 +1,11 @@ #!/usr/bin/env bash -pbin="" -fl=$(readlink $0) -if [[ -z "$fl" ]]; then - pbin=$(dirname $0) - else - pbin=$(dirname $fl) -fi -export PATH=$pbin:$PATH -$pbin/tophat "$@" +# http://stackoverflow.com/a/246128: +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +export PATH=$DIR:$PATH +$DIR/tophat "$@"