标签:shell
如果大家接触过c语言应该知道,c语句在执行时如果遇到错误编辑器会指出具体的错误在那一行,当然这些错误是机器不能不能执行的错误!很遗憾我们的shell脚本语言中貌似没有这样的功能,但是shell脚本也为我们提供了3种方式来帮助我们检查错误!
我们依次来看一下:首先是检测语法错误:
[root@lvs ~]# sh -n 1.sh 1.sh: line 11: syntax error near unexpected token `done‘ 1.sh: line 11: `done‘ [root@lvs ~]# cat 1.sh #!/bin/bash while :; do read -p "Please input a number: " a b=`echo $a |sed ‘s/[0-9]//g‘ | wc -c` if [ $b = 1 ];then echo $a exit else continue # fi /注释掉了这一行 done [root@lvs ~]#
来看一下vebose模式:
[root@lvs ~]# sh -v 1.sh #!/bin/bash while :; do read -p "Please input a number: " a b=`echo $a |sed ‘s/[0-9]//g‘ | wc -c` if [ $b = 1 ];then echo $a exit else continue fi done Please input a number: re echo $a |sed ‘s/[0-9]//g‘ | wc -c Please input a number: dfgfd echo $a |sed ‘s/[0-9]//g‘ | wc -c
接下来看一下trace模式:
[root@lvs ~]# sh -x 1.sh + : + read -p ‘Please input a number: ‘ a Please input a number: erw ++ wc -c ++ sed ‘s/[0-9]//g‘ ++ echo erw + b=4 + ‘[‘ 4 = 1 ‘]‘ + continue + : + read -p ‘Please input a number: ‘ a Please input a number: 43 ++ wc -c ++ sed ‘s/[0-9]//g‘ ++ echo 43 + b=1 + ‘[‘ 1 = 1 ‘]‘ + echo 43 43 + exit [root@lvs ~]#
本文出自 “自定义” 博客,谢绝转载!
标签:shell
原文地址:http://zidingyi.blog.51cto.com/10735263/1771287