Tuesday, February 06, 2007

Run Debugger and Verbose Modes in a Script

We write scripts frequently and occassionally they are stricken with a few bugs. Most of our scripts are written in Bourne Shell. To debug in the verbose mode, we append the -xv options to /usr/bin/sh.

Here's a demo script to illustrate the aforementioned comments.

#!/usr/bin/sh -xv
#Name: SampleScript
#Purpose: Demonstrate debug and verbose options.
#
#Menu
echo "Choose either P, D, Q "
echo "[P]rint"
echo "[D]elete"
echo "[Q]uit"

#Get letter from user
read letter
#Match response
case $letter
in
P|p) echo "Name of file to print."
read file
lp $file;;
D|d) echo "Name of file to delete."
read file
rm $file;;
*) echo "Quitting program";;
esac

No comments: