I think a readlink -f $0
to reveal the target of the shell script itself, then a dirname
to strip off the script, then another readlink -f
on the product of that should do the trick:
PROGUARD_HOME=$(readlink -f $(dirname $(readlink -f "$0"))/..)
A more step-by-step breakdown:
echo "\$0 is $0"
TRUENAMEOFSCRIPT=$(readlink -f $0)
echo "readlink -f of \$0 reveals $TRUENAMEOFSCRIPT"
DIRNAMEOFSCRIPT=$(dirname $TRUENAMEOFSCRIPT)
echo "The script lives in directory $DIRNAMEOFSCRIPT"
PARENTDIR=$(readlink -f "$DIRNAMEOFSCRIPT"/..)
echo "Its parent dir is $PARENTDIR"