If you have been exposed to the C language, you should know that the C statement is executed when the error editor will indicate the specific error in that line, of course, these errors are the machine can not be executed error! Unfortunately our Shell scripting language does not seem to have such a feature, but the shell script also provides us with 3 ways to help us check for errors!
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7F/D7/wKiom1cvRZTAT9hhAAC4Gddt4fE321.png "title=" 1.png " alt= "Wkiom1cvrztat9hhaac4gddt4fe321.png"/>
Let's look at it in turn: First, the syntax error is detected:
[Email protected] ~]# sh-n 1.sh 1.sh:line 11:syntax error near unexpected tokens ' done ' 1.sh:line one: ' Done ' [[Email Pro Tected] ~]# cat 1.sh #!/bin/bashwhile:; Doread-p "Please input a number:" Ab= ' echo $a |sed ' s/[0-9]//g ' | Wc-c ' if [$b = 1];thenecho $aexitelsecontinue #fi/commented out this line Done[[email protected] ~]#
Take a look at the Vebose mode:
[Email protected] ~]# sh-v 1.sh #!/bin/bashwhile:; Doread-p "Please input a number:" Ab= ' echo $a |sed ' s/[0-9]//g ' | Wc-c ' if [$b = 1];thenecho $aexitelsecontinuefidonePlease input a number:reecho $a |sed ' s/[0-9]//g ' | Wc-cplease input a Number:dfgfdecho $a |sed ' s/[0-9]//g ' | Wc-c
Now look at the trace pattern:
[Email protected] ~]# sh-x 1.sh +: + read-p ' Please input a number: ' Aplease input a number:erw++ wc-c++ sed ' s/[0-9 ]//g ' + + echo erw+ b=4+ ' [' 4 = 1 '] ' + continue+: + read-p ' Please input a number: ' Aplease input a number:43++ wc-c++ Sed ' s/[0-9]//g ' + echo 43+ b=1+ ' [' 1 = 1 '] ' + echo 4343+ exit[[email protected] ~]#
This article is from "Custom" blog, declined reprint!
Shell---------Debug Mode