bash get the path of the currently running script files

References: https://sexywp.com/bash-how-to-get-the-basepath-of-current-running-script.htm

Specific script as follows:

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

Will determine whether the current file is a soft link file, if it is, get a real document;

Guess you like

Origin www.cnblogs.com/xn--gzr/p/10988608.html