/de">/de" />
<span id='2kef0'></span>

<code id='2kef0'><strong id='2kef0'></strong></code>
<i id='2kef0'></i>

  • <dl id='2kef0'></dl>
    <ins id='2kef0'></ins>

      <acronym id='2kef0'><em id='2kef0'></em><td id='2kef0'><div id='2kef0'></div></td></acronym><address id='2kef0'><big id='2kef0'><big id='2kef0'></big><legend id='2kef0'></legend></big></address>
    1. <tr id='2kef0'><strong id='2kef0'></strong><small id='2kef0'></small><button id='2kef0'></button><li id='2kef0'><noscript id='2kef0'><big id='2kef0'></big><dt id='2kef0'></dt></noscript></li></tr><ol id='2kef0'><table id='2kef0'><blockquote id='2kef0'><tbody id='2kef0'></tbody></blockquote></table></ol><u id='2kef0'></u><kbd id='2kef0'><kbd id='2kef0'></kbd></kbd>
        <i id='2kef0'><div id='2kef0'><ins id='2kef0'></ins></div></i>

          <fieldset id='2kef0'></fieldset>
          1. linux获取shell脚本所在绝对路径操作介绍

            • 时间:
            • 浏览:4
            • 来源:124软件资讯网

                剧本名:a.sh

                位置:/tmp/whuang/study/java

                剧本内容:

                代码如下:

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

                ----------------------------------------------

                功效:获取剧本的绝对路径 。

                测试:

                [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