Shell---------Debug Mode

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.