Shell获取脚本所在目录的方法

SHELLLINUX2015-06-30 16:54
SWD=$(dirname $(which $0)) && cd "$SWD"
pwd

path1=$(which $0)
path1=$(cd ${path1%/*}; pwd)
echo ${path1%/*}
pwd

path2=$(cd "$(dirname "$0")"; pwd)
echo $(dirname $path2)
pwd

path3=$(dirname $(readlink -f $0))
echo $(dirname $path3)
pwd

原文链接: http://blog.jtwo.me/get-shell-script-directory