bash 获取当前运行文件脚本的路径
参考文件:https://sexywp.com/bash-how-to-get-the-basepath-of-current-running-script.htm
具体脚本如下:
1 #!/bin/bash 2 if [ -L $0 ] 3 then 4 BASE_DIR=`dirname $(readlink $0)` 5 else 6 BASE_DIR=`dirname $0` 7 fi 8 basepath=$(cd $BASE_DIR; pwd) 9 echo $basepath
会判断当前文件是否是软链接文件,若是则,获取真正的文件;