Hour 20

1: What are the three main forms of enabling debugging in a shell script?
A1: The three main methods are
  • Issue the script in the following fashion:

    $ /bin/sh option
    											script
    											arg1
    											arg2
    											arg3
    										
  • Change the first line of the script to

    #!/bin/sh option
    										
  • Use the set command as follows:

    set option
    										

Here option is the debugging option you want to enable.

2: Enhance the Debug() function given in this chapter so that the programmer has to press Enter or Return after debugging is deactivated.

When you debug scripts that have several dozen functions, this feature enables you to study the debugging output from a particular function before executing the next function.

A2: Here is one possible implementation:
 Debug() { if [ "$DEBUG" = "true" ] ; then if [ "$1" ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.