借鉴别人的方法,记录一下。(参考链接:/bash-how-to-get-the-basepath-of-current-running-script.htm)
#! /bin/bash# get all filename in special pathpath=$(cd `dirname $0`; pwd) //此处是获取当前目录echo "we are now at: $path"files=$(ls $path)for file in $filesdoecho $filedone
dirname $0,取得当前执行的脚本文件的父目录
cd `dirname $0`,进入这个目录(切换当前工作目录)
pwd,显示当前工作目录(cd执行后的)