shell脚本学习总结11--脚本调试
2016-08-21 02:30
701 查看
参数:
-n 不执行脚本,仅检查语法是否错误
-v 将脚本内容输出到屏幕上,然后执行脚本
-x 执行脚本,并将内容输出到屏幕
-n
-v
-x
拓展:
利用PS4,使调试时输出行号
利用set ,缩小调试作用域
set -x 开启调试功能
set +x 关闭调试功能
-n 不执行脚本,仅检查语法是否错误
-v 将脚本内容输出到屏幕上,然后执行脚本
-x 执行脚本,并将内容输出到屏幕
-n
[root@new sbin]# sh -n debug.sh [root@new sbin]#
-v
[root@new sbin]# sh -v debug.sh 10 module () { eval `/usr/bin/modulecmd bash $*` } #/bin/bash if [ $1 -gt 5 ];then echo "yes" else echo "no" fi yes
-x
[root@new sbin]# sh -x debug.sh + '[' -gt 5 ']' debug.sh: line 2: [: -gt: unary operator expected + echo no no
拓展:
利用PS4,使调试时输出行号
[root@new sbin]# echo $PS4 + [root@new sbin]# export PS4='+{$LINENO}'[root@new sbin]# sh -x debug.sh 4 +{2}'[' 4 -gt 5 ']' +{5}echo no no
利用set ,缩小调试作用域
set -x 开启调试功能
set +x 关闭调试功能
[root@new sbin]# cat demo.sh #/bin/bash . /etc/init.d/functions set -x read -p "Pleas input your anwser[yes/no]: " an set +x if [[ $an = yes ]] then action "The answer is true" /bin/true else action "Then answer is false" /bin/false fi [root@new sbin]# sh demo.sh +{4}read -p 'Pleas input your anwser[yes/no]: ' an Pleas input your anwser[yes/no]: yes +{5}set +x The answer is true [ OK ]
相关文章推荐
- shell脚本学习与总结
- shell 脚本菜鸟学习总结
- shell脚本学习总结02--数组
- shell脚本学习总结09--分支与循环结构
- shell脚本学习总结06--数学计算
- shell脚本学习-11(cut命令学习)
- shell脚本学习总结
- shell脚本学习总结03--别名的使用
- 【Shell脚本学习11】Shell注释
- Ubuntu学习总结-08 Ubuntu运行Shell脚本报 shell /bin/bash^M: bad interpreter错误问题解决
- BASH命令和SHELL脚本总结(11)比较两个文件创建时间的先后
- shell脚本教程学习总结,perfect!
- shell脚本学习与总结
- shell脚本学习总结04--终端信息的获取和设置
- 顶嵌学员学习笔记:Shell脚本编程总结
- shell脚本学习总结
- shell脚本学习总结-----第一篇
- shell学习:内部字段分隔符IFS、脚本调试DEBUG
- shell脚本学习总结08--比较与测试