首页 > 系统服务 > 详细

shell脚本使用技巧3--调试

时间:2017-06-10 12:04:58      阅读:182      评论:0      收藏:0      [点我收藏+]

1.使用-x,开启shell脚本的跟踪调试功能

ex:bash -x script.sh

or

sh -x script.sh

2.使用set -x 和 set +x对脚本进行部分调试(输入中间的内容)

#!/bin/bash
#filename:debug.sh
for i in {1..6};
do
    set -x
    echo $i
    set +x
done
echo "script executed"

3.固定格式生成调试信息

注:符号:告诉shell不要进行任何操作

#!/bin/bash
function DEBUG()
{
   [ "$_DEBUG" == "on" ] && $@ || : 
 
}
for i in {1..10}
do
    DEBUG echo $i
done

执行命令:_DEBUG=on ./script.sh

4.修改脚本开头#!/bin/bash 为#!/bin/bash -xv自动开启调试功能;

 

shell脚本使用技巧3--调试

原文:http://www.cnblogs.com/hujianglang/p/6978161.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!