Saturday, January 1, 2011

Shell Script App Dir

#! /bin/sh

if [ "$APPHOME" = "" ] ; then
# try to locate application home directory

## resolve links - $0 may be a link to the app home
PRG=$0
progname=`basename $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

export APPHOME=`dirname "$PRG"`/..
export APPHOME=$(cd $APPHOME >/dev/null; pwd)
fi

No comments:

Post a Comment