TC shell scripts often fail due to some simple syntax error or logic error. Options to the tcsh command are provided to help you debug your programs. See Table 11.3.
As options to tcsh | |
tcsh -x scriptname | Display each line of script after variable substitution and before execution. |
tcsh -v scriptname | Display each line of script before execution, just as you typed it. |
tcsh -n scriptname | Interpret but do not execute commands. |
As arguments to the set command | |
set echo | Display each line of script after variable substitution and before execution. |
set verbose | Display each line of script before execution, just as you typed it. |
As the first line in a script | |
#!/bin/tcsh -xv | Turn on both echo and verbose. These options can be invoked separately or combined with other csh invocation arguments. |
(The -v and -x Options) 1 > cat practice #!/bin/tcsh -f echo Hello $LOGNAME echo The date is `date` echo Your home shell is $SHELL echo Good-bye $LOGNAME 2 > tcsh -v practice echo Hello $LOGNAME Hello ellie echo The date is `date` The date is Mon May 24 12:26:07 PDT 2000 echo Your login shell is $SHELL Your login shell is /bin/csh echo Good-bye $LOGNAME Good-bye ellie 3 > tcsh -x practice echo Hello ellie Hello ellie echo The date is `date` date The date is Mon May 24 12:26:15 PDT 2000 echo Your login shell is /bin/tcsh Your login shell is /bin/tcsh echo Good-bye ellie Good-bye ellie |
Explanation
The contents of the TC shell script are displayed. Variable and command substitution lines are included so that you can see how echo and verbose differ.
The -x option to the tcsh command enables echoing. Each line of the script is displayed after variable and command substitution are performed, and then the line is executed. Because this feature allows you to examine what is being replaced as a result of command and variable substitution, it is used more often than the verbose option.
(Echo and Verbose) 1 > cat practice #!/bin/tcsh -f echo Hello $LOGNAME echo The date is `date` set echo echo Your home shell is $SHELL unset echo echo Good-bye $LOGNAME 2 > chmod +x practice 3 > practice Hello ellie The date is Mon May 24 12:25:16 PDT 2000 -->echo Your login shell is /bin/tcsh -->Your login shell is /bin/tcsh -->unset echo Good-bye ellie |
Explanation
The echo option is set and unset within the script. This enables you to debug certain sections of your script where you have run into a bottleneck, rather than echoing each line of the entire script.
The execute permission is turned on with chmod.
The --> marks where the echoing was turned on. Each line is printed after variable and command substitution and then executed.
1 > cat practice #!/bin/tcsh -f echo Hello $LOGNAME echo The date is `date` set verbose echo Your home shell is $SHELL unset verbose echo Good-bye $LOGNAME 2 > practice Hello ellie The date is Mon May 24 12:30:09 PDT 2000 -->echo Your login shell is $SHELL -->Your login shell is /bin/csh -->unset verbose Good-bye ellie |
Explanation
The verbose option is set and unset within the script.
The --> marks where verbose was turned on. The lines are printed just as they were typed in the script and then executed.
3.149.29.71