shell: 10、獲取實際路徑
# 在某些情況下會拿到錯誤結果
work_path=$(dirname $0)
work_path=$(pwd)
## 正確實現
# 通過 readlink 獲取絕對路徑,再取出目錄
work_path=$(dirname $(readlink -f $0))
# 或者曲線救國
work_path=$(dirname $0)
cd ./${work_path} # 當前位置跳到腳本位置
work_path=$(pwd) # 取到腳本目錄
# 在某些情況下會拿到錯誤結果
work_path=$(dirname $0)
work_path=$(pwd)
## 正確實現
# 通過 readlink 獲取絕對路徑,再取出目錄
work_path=$(dirname $(readlink -f $0))
# 或者曲線救國
work_path=$(dirname $0)
cd ./${work_path} # 當前位置跳到腳本位置
work_path=$(pwd) # 取到腳本目錄