参数:

-n    不执行脚本,仅检查语法是否错误

-v    将脚本内容输出到屏幕上,然后执行脚本

-x   执行脚本,并将内容输出到屏幕

-n

[root@new sbin]# sh -n debug.sh 
[root@new sbin]#

-v

[root@new sbin]# sh -v debug.sh
module () { eval `/usr/bin/modulecmd bash $*`
}
#/bin/bash
if [ $ -gt ];then
echo "yes"
else
echo "no"
fi
yes

-x

[root@new sbin]# sh -x debug.sh
+ '[' -gt ']'
debug.sh: line : [: -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
+{}read -p 'Pleas input your anwser[yes/no]: ' an
Pleas input your anwser[yes/no]: yes
+{}set +x
The answer is true [ OK ]

shell脚本学习总结11--脚本调试的更多相关文章

  1. sh脚本学习之: sh脚本 、sed、awk

    sh脚本 sh命令的批处理文件,支持更复杂的逻辑. Shell中的变量 参数 $0 当前脚本路径 $1....$n 脚本执行对应的第n个参数 条件判断 文件判断 test [op] path e存在 ...

  2. 【Shell 编程基础第二部分】Shell里的流程控制、Shell里的函数及脚本调试方法!

    http://blog.csdn.net/xiaominghimi/article/details/7603003 本站文章均为李华明Himi原创,转载务必在明显处注明:转载自[黑米GameDev街区 ...

  3. 转 shell脚本学习指南

    shell脚本学习指南 以下八点不敢说就能成为你shell脚本学习指南de全部,至少可以让你编写出可靠的shell脚本. 1. 指定bashshell 脚本的第一行,#!之后应该是什么?如果拿这个问题 ...

  4. shell 脚本学习

    Shell简介 概述 Shell是一种具备特殊功能的程序,它提供了用户与内核进行交互操作的一种接口.它接收用户输入的命令,并把它送入内核去执行.内核是Linux系统的心脏,从开机自检就驻留在计算机的内 ...

  5. Shell脚本学习之expect命令

     转载:http://blog.csdn.net/leexide/article/details/17485451 目录(?)[-] 一概述 二expect的安装 一Tcl 安装 二expect 安装 ...

  6. 【shell脚本学习-1】

    Shell学习笔记 简介: Shell 是一个用C语言编写的程序,它是用户使用Linux的桥梁.Shell既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个 ...

  7. Shell脚本学习指南笔记

    Shell脚本学习指南 作者:Danbo 2015-8-3 脚本编程语言与编译型语言的差异 许多中型.大型的程序都是用编译型语言写的,例如:C.C+.Java等.这类程序只要从源代码(Source C ...

  8. shell脚本学习之6小时搞定(1)

    shell脚本学习之6小时搞定(1) 简介 Shell是一种脚本语言,那么,就必须有解释器来执行这些脚本. Unix/Linux上常见的Shell脚本解释器有bash.sh.csh.ksh等,习惯上把 ...

  9. Shell脚本学习第二课·

    Shell文件包含 shell也可以包含外部脚本,语法格式如下: . filename 或 source filename 例如创建两个shell脚本. 脚本1:test1.sh url = &quo ...

随机推荐

  1. Linux命令-文件处理命令:more

    分页查看文件命令,区别于翻页查看文件命令less more /etc/services 查看etc目录中的services文件 注意:空格或f是翻页,回车Enter是换行,q或Q是退出.

  2. C#获取文件的md5

    上代码: //获取MD5 public static string GetMd5Hash(String input) { if (input == null) { return null; } MD5 ...

  3. C#:数据库操作(待补充)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  4. TensorFlow 简单实例

    TF 手写体识别简单实例: TensorFlow很适合用来进行大规模的数值计算,其中也包括实现和训练深度神经网络模型.下面将介绍TensorFlow中模型的基本组成部分,同时将构建一个CNN模型来对M ...

  5. win10 配置 python3 + opencv3.2 + VideoCapture

    最近需要在 win10 上进行图片处理,使用深度学习框架 tensorflow ,所以安装了python3.5 + opencv3.2 + tensorflow + VideoCapture + PI ...

  6. 32位嵌入式微处理器(processor)一览

    32位嵌入式微处理器(processor)一览 由于嵌入式系统的专用型与定制性,与全球PC市场不同,没有一种微处理器或者微处理器公司可以主导嵌入式系统.本文分析了当前市场上主流的一些32位嵌入式微处理 ...

  7. 实用crontab命令

    常用crontab如下: crontab -e 编辑 crontabcrontab -l  显示 crontabcrontab -r  删除 crontabcrontab -v 显示上一次编辑 cro ...

  8. 线程相关函数(4)-pthread_mutex_lock(), pthread_mutex_unlock() 互斥锁

    互斥锁实例: #include <pthread.h>pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;int pthread_mutex ...

  9. JS 遍历 json key ,获取设置可变的key

    $(rec.data[id]).each(function(){ for(var key in this){ if(key == value){ console.info(this[key].desc ...

  10. Java callback

    Java中的回调(callback)是很重要的一个概念,spring整合hibernate大量使用了这种技术. 究竟怎样才是回调呢? 这是网上最多见到的说明:     1.class   A,clas ...