VMS-to-Unix Phrase Book
<=  Return           

1.7  Debugging Scripts

Problem

You want to see commands in a initialization (or other) script, as they are being executed.

Solution

Use the -xv shell options. This is similar in effect to the DCL command SET VERIFY.

Discussion

The -x shell option prints commands and their arguments as they are executed. The -v option prints shell input lines (i.e. the script's source code lines) as they are read.

There are three basic ways of turning on script verification:

  1. Invoke the shell with these options on the command line.

    unix> sh -xv myScript.sh | more
    
    Be forewarned that just like SET VERIFY this can produce a lot of output, so you may want to pipe the resulting text through a pager or redirect it to a temp file.

  2. Invoke the options on the initial 'shebang' line of the script:

         #!/bin/sh -xv
    (See 3.1 for more information about the shebang line.)

  3. Use the ksh set command to turn these options on and off as needed:

         set -x;   # Turn on tracing with variable substitution...
          :
          :
         unset -x; # Turn off tracing...

See Also

3.1 - Creating Shell Scripts;
Chapter 10 of Unix for OpenVMS Users ;
Chapter 48 of Unix Power Tools .


<=  Return           

Colophon:
Best Viewed With Any Browser
This page maintained by:
    Bill.Costa@unh.edu
    of the Enterprise Computing Group
    in the dept of Computing & Information Sevices
    at the University of New Hampshire

Typographical
Conventions

Created:  31-Jan-2001 BC
Revised:  27-Mar-2001 BC