Debugging Techniques for Shell scripts

Source: Internet
Author: User

The essential point in programming is debugging, Shell script with its powerful function is desirable, of course, its powerful is not only embodied in the language of the implementation function, more powerful is its debugging function, below, I will illustrate the shell script debugging technology.

Here are the examples I used:

#!/bin/bash   
line= "Tests run:196,  failures:1,  errors:1"
error= ' echo $LINE |cut-d ': '-f4 '  
echo $ Error  
error=0
error=$ (($error + $ERROR))  
Echo $ERROR

There are two ways to run this example:

1. Add execution permissions to the file chmod a+x sleep.sh

2. Perform SH sleep.sh as command line parameters

The results of the operation are shown in the following illustration:

As we can see, this shows only the execution results, so what if I wanted to know how the script was executed?

There are also two ways to use:

1. Add the corresponding parameters at run time

Bash-x sleep.sh

2. Add the appropriate information at the beginning of the script file

#!/bin/bash-xv  
line= "Tests run:196,  failures:1,  errors:1" error= '
echo $LINE |cut-d ': '-f4 '  
Echo $error  
Error=0
error=$ (($error + $ERROR))  
Echo $ERROR

We can see that the first line joins the-XV

Let's run this script one more time, and the results are as follows:

Here I'm done with the shell script debugging.

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.