echo "Get the current path: `dirname "$PRG"`" # 判断软连接是否在当前目录下 if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG="`dirname "$PRG"`/$link" fi
$./xx.sh Current script PRG: ./xx.sh Soft connection path link: aa/bb/cc/xx.sh Get the current path: . Soft connection path link: aa/bb/cc/xx.sh Actual script path PRG: ./aa/bb/cc/xx.sh