Get Script Path in Shell
Posted bob
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Get Script Path in Shell相关的知识,希望对你有一定的参考价值。
#!/usr/bin/bash
dir_old=$(pwd)
absolute_script_path=$(cd $(dirname $0) && pwd)
relative_script_path=$(dirname $0)
wrong_absolute_script_path=$dir_old/$relative_script_path
echo "Current PATH: $dir_old"
echo "absolute_script_path is: $absolute_script_path"
echo "relative_script_path is: $relative_script_path"
echo "This path might be wrong: $wrong_absolute_script_path"
# Fail if use absolute path to invoke script
cd $wrong_absolute_script_path && pwd
以上是关于Get Script Path in Shell的主要内容,如果未能解决你的问题,请参考以下文章