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.