|Lesson 3||Tracing shell scripts|
|Objective||Use shell options to test each line of a script.|
voptions locate many, but not all, errors in a script
voption displays each line of your script before it is run. It prints the line exactly as you included it in your script
voption shows you which option your script is running. The
voption helps when your script is producing no output and appears to be in an infinite loop. You must press CTRL + C to stop this sort of script. ]
xoption displays each line with all variables translated into their values. This is helpful when your script uses variables. To debug a problem, you must know which values your script is using in its commands.
sortcommand. This produces no error message because it is not a syntax error . This is the kind of error that the
xoption helps you locate. Look through the FlipBook to see how the
xoption locates this error.
voptions for just a portion of your script. Here is more information about tracing a portion of a script
set vinside your script prints each line before it is run. Use
set +vto turn off this feature. You can do the same thing with
set +xto show lines of code with their variables translated.
set vare combined into one statement to turn on both options in the middle of the script: #!
/bin/sh echo "Please enter name of new user: " read filename
set xv sort $filename | cat n > tempfile cp tempfile $filename set +xv echo "Your file is now sorted"