?? 在bin下面有9個sh文件,本文將逐步分析,今天就以version.sh為例
??
os400= false #uname取操作系統名稱 如Linux 如果為OS400的操作系統 特殊處理 case " `uname` " in OS400 *) os400= true ;; esac # resolve links - $ 0 may be a softlink # 解析文件或者符號文件 得到真正文件 # /home/dragonsuc/bin/version. sh # /home/dragonsuc/bin/tm ->/home/dragonsuc/bin/version. sh #當以符號連接啟動時 找到真正文件 /home/dragonsuc/bin/version. sh #取得當前執行文件名稱 PRG = " $0 " #判斷文件是否是符號文件 文件存在并且是符號文件 while [ -h " $PRG " ] ; do # lr 。。。。 /home/dragonsuc/bin/tm ->/home/dragonsuc/bin/version. sh ls =` ls - ld " $PRG " ` # 注意下面兩行中expr精妙用法 # 得到 /home/dragonsuc/bin/version. sh link =` expr " $ls " : ' .*-> \(.*\)$ ' ` if expr " $link " : ' /.* ' > /dev/ null ; then PRG = " $link " else PRG =` dirname " $PRG " `/ " $link " fi done #得到目錄路徑 /home/dragonsuc/ bin PRGDIR =` dirname " $PRG " ` EXECUTABLE =catalina. sh # Check that target executable exists if $os400; then # -x will Only work on the os400 if the files are: # 1 . owned by the user # 2 . owned by the PRIMARY group of the user # this will not work if the user belongs in secondary groups eval else #測試文件的可執行權限 if [ ! -x " $PRGDIR " / " $EXECUTABLE " ]; then echo " Cannot find $PRGDIR/$EXECUTABLE " echo " The file is absent or does not have execute permission " echo " This file is needed to run this program " exit 1 fi fi # 執行文件 $@是傳遞執行的參數 exec " $PRGDIR " / " $EXECUTABLE " version " $@ "
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
