#!/usr/bin/env bash
BASE_DIR="$(pwd)"
function get_script_dir {
# resolve links - $0 may be a softlink
PRG="$0"
while [ -h "$PRG" ]; do #-h 文件存在并且是一个字符链接
ls=`ls -ld "$PRG"`
link=`expr "$ls" : ‘.*-> \(.*\)$‘`
if expr "$link" : ‘/.*‘ > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
PRGDIR=`dirname "$PRG"`
pushd $PRGDIR &> /dev/null
BASE_DIR=$(pwd)
popd &> /dev/null
}
# get script‘s directory
get_script_dir
原文:https://www.cnblogs.com/lsw-blogs/p/10942018.html