欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

linux獲取shell腳本所在絕對(duì)路徑操作介紹

  發(fā)布時(shí)間:2012-11-16 10:47:45   作者:佚名   我要評(píng)論
本文將詳細(xì)介紹linux在shell腳本中獲取該腳本的所在絕對(duì)路徑的操作方法,需要的朋友可以參考下
腳本名:a.sh
位置:/tmp/whuang/study/java
腳本內(nèi)容:

復(fù)制代碼
代碼如下:

#!/bin/sh
this_dir=`pwd`
dirname $0|grep "^/" >/dev/null
if [ $? -eq 0 ];then
this_dir=`dirname $0`
else
dirname $0|grep "^\." >/dev/null
retval=$?
if [ $retval -eq 0 ];then
this_dir=`dirname $0|sed "s#^.#$this_dir#"`
else
this_dir=`dirname $0|sed "s#^#$this_dir/#"`
fi
fi
echo $this_dir

----------------------------------------------
功能:獲取腳本的絕對(duì)路徑。
測(cè)試:

[root@ppc40 java]# pwd
/tmp/whuang/study/java
[root@ppc40 java]# sh a.sh
/tmp/whuang/study/java
[root@ppc40 java]# cd ..
[root@ppc40 study]# sh java/a.sh
/tmp/whuang/study/java
[root@ppc40 study]# sh ./java/a.sh
/tmp/whuang/study/java

相關(guān)文章

最新評(píng)論