Shell script learning-simple execution tracking

Source: Internet
Author: User
Tags echo command

ProgramIt is written by humans, and errors are inevitable. If you want to know what your program is doing, there is a good way to enable the trace execution function. This causes the shell to display each executed command and add "+" to the front. A plus sign is followed by a space.

In the script, use the set-x command to open the trace execution function, and then use the set + x command to close it. This function is useful for complex scripts. However, we only use simple programs to describe it:

 
Cat>Trace1.sh#! /Bin/shSet-X#Enable trackingEcho 1st echo#Do somethingSet+ X#Disable trackingEcho 2nd echo#Do something more^ D#End with end-of-File
Chmod +X trace1.sh./Trace1.sh+ Echo 1st echo#The first line to be tracked1st echo#Command output+ Sex + x#Next row tracked2nd echo#Output of the next command

During execution, set-X will not be tracked because the tracing function is enabled only after the command is executed. Similarly, sex + X will be tracked because the tracking function is disabled only after this command is executed. The last echo command is not tracked because the tracking function is disabled.

Related Article

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.