Control output based on debugging levels

Source: Internet
Author: User

Set a debugging variable at the beginning of the script. When the script is running, test the variable and decide whether to display or disable the debugging command based on the value of the variable. As follows:

#! /Bin/sh
DEBUG = 1
Test $ debug-GT 0 & Echo "Debug is on"
Echo-n "can you write device drivers? "
Read answer
Test $ debug-GT 0 & Echo "The answer is $ answer"

Answer = 'echo $ answer | tr [A-Z] [A-Z]'

If [$ answer = 'y']
Then
Echo "Wow, you must be very skilled"
Test $ debug-GT 0 & Echo "The answer is $ answer"
Else
Echo "neither can I, I'm just an example shell script"
Test $ debug-GT 0 & Echo "The answer is $ answer"
Fi

You can change the debugging level by changing the dubug value. For example:

DEBUG = 2
Test $ debug-GT 0 & Echo "a litter data"

Test $ debug-GT 1 & Echo "some more data"

Test $ debug-GT 2 & Echo "even some more data"

You can also change-GT to-EQ.

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.