月度存档: 3月 2017

脚本获得当前所在的目录

写脚本时经常需要获取当前执行的脚本所在的目录。

我最早使用的是:

shellPath=`echo $PWD/``echo ${0%/*}`

今天在做一个远程执行脚本时才发现,如果执行脚本时使用绝对路径,上面会得到错误的路径,现修改如下,可同时支持相对路径和绝对路径执行脚本:

shellPath=`echo $PWD/``echo ${0%/*}`

# process absolute path
shellPath1=`echo $PWD/`
shellPath2=`echo ${0%/*}`
if [ ${shellPath2:0:1} == '/' ] ; then
    shellPath=${shellPath2}
fi

Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /opt/wordpress/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048