码迷,mamicode.com
首页 > 系统相关 > 详细

Get Script Path in Shell

时间:2016-11-12 18:58:49      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:abs   relative   absolute   path   bash   wro   amp   name   current   

#!/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

标签:abs   relative   absolute   path   bash   wro   amp   name   current   

原文地址:http://www.cnblogs.com/xiaochou/p/Get_Script_Path_in_Shell.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!