- #!/bin/sh
-
-
#change to the directory in which this script resides
-
-
cd `dirname $0`
-
-
#just to show it worked right
-
-
pwd
-
-
#save
-
-
TOPDIR=`pwd`
补充:如果使用soft link方式运行脚本,如何获得真实脚本所在的目录呢?
答案在:
解决方案就是这个脚本:
SCRIPT_PATH="${BASH_SOURCE[0]}";
if ([ -h "${SCRIPT_PATH}" ]) then
while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
fi
pushd . > /dev/null
cd `dirname ${SCRIPT_PATH}` > /dev/null
SCRIPT_PATH=`pwd`;
popd > /dev/null