全部博文(42)
分类:
2010-09-08 14:51:51
Using the set Bash built-in you can run in normal mode those portions of the script of which you are sure they are without fault, and display debugging information only for troublesome zones. Say we are not sure what the w command will do in the example commented-script1.sh, then we could enclose it in the script like this:
set -x # activate debugging from here w set +x # stop debugging from here |
Table 2-1. Overview of set debugging options
Short notation | Long notation | Result |
---|---|---|
set -f | set -o noglob | Disable file name generation using metacharacters (globbing). |
set -v | set -o verbose | Prints shell input lines as they are read. |
set -x | set -o xtrace | Print command traces before executing command. |
The dash is used to activate a shell option and a plus to deactivate it. Don't let this confuse you!
In the example below, we demonstrate these options on the command line:
willy:~/scripts> set -v willy:~/scripts> ls ls commented-scripts.sh script1.sh willy:~/scripts> set +v set +v willy:~/scripts> ls * commented-scripts.sh script1.sh willy:~/scripts> set -f willy:~/scripts> ls * ls: *: No such file or directory willy:~/scripts> touch * willy:~/scripts> ls * commented-scripts.sh script1.sh willy:~/scripts> rm * willy:~/scripts> ls commented-scripts.sh script1.sh |
chinaunix网友2010-09-10 10:59:07
很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com
chinaunix网友2010-09-10 09:36:42
Download More than 1000 free IT eBooks: http://free-ebooks.appspot.com