sh 获取当前运行脚本的包含目录,存储为$ dir

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 获取当前运行脚本的包含目录,存储为$ dir相关的知识,希望对你有一定的参考价值。

# foolproof way to figure out where this script is placed
source="${BASH_SOURCE[0]}"
while [ -h "$source" ]; do # resolve $source until the file is no longer a symlink
  dir="$( cd -P "$( dirname "$source" )" && pwd )"
  source="$(readlink "$source")"
  # if $source was a relative symlink, we need to resolve it relative
  # to the path where the symlink file was located
  [[ $source != /* ]] && source="$dir/$source"
done
dir="$( cd -P "$( dirname "$source" )" && pwd )" #dir now has the script locat'n

以上是关于sh 获取当前运行脚本的包含目录,存储为$ dir的主要内容,如果未能解决你的问题,请参考以下文章

tomcat优化脚本

sh 获取当前脚本的目录

shell脚本获取绝对目录

从 qmake 运行脚本以获取内部版本号

20180209-os模块

21.os模块