C-type shells have two variables that, when set, will help you follow the convoluted trail of variable and metacharacter expansion. This command will echo every command line before shell variables have been evaluated:
set Section 35.9
% set verbose
This command will display each line after the variables and metacharacters have been substituted:
% set echo
If you wish to turn the options off, use unset (Section 35.9) instead of set.
Bourne-type shell syntax is different. To turn on the verbose flag, use:
$ set -v
The command set -x turns on the echo flag. You can also type them together: set -xv.
If your version of Unix understands scripts that start with #!, and nearly all do, here's a convenient way to turn these variables on from the first line of a script:
#!/bin/sh -xv
It is not necessary to modify the program. You can enable variable tracing in Bourne shell scripts by typing the shell name and options on the command line:
$ sh -v script $ sh -x script
Not all Bourne shells let you turn these options off. If yours does (and it probably does), you can do it by using a plus sign instead of a minus sign:
set +xv
Copyright © 2003 O'Reilly & Associates. All rights reserved.