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.