在目录/home/baidu/bao下
有shell文件test_shell.sh
echo `date` just 4 test >> test_shell.log
在/home/baidu/bao/will下执行shell脚本
最后会在/home/baidu/bao/will 文件夹下产生 日志文件test_shell.log
要想仍然在上面的/home/baidu/bao/will下执行shell脚本
但是要求test_shell.log生成所在目录/home/baidu/bao/文件夹下产生日志文件test_shell.log
怎么弄?
可以在shell脚本里添加cd `dirname $0`
即
cd `dirname $0`
echo `date` just 4 test >> test_shell.log
OK!