Chinaunix首页 | 论坛 | 博客
  • 博客访问: 133468
  • 博文数量: 42
  • 博客积分: 2521
  • 博客等级: 少校
  • 技术积分: 440
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-31 21:29
文章分类

全部博文(42)

文章存档

2011年(1)

2010年(33)

2009年(8)

我的朋友

分类:

2010-09-08 14:51:51

1.Turn on debug option
 
Bash provides extensive debugging features. The most common is to start up the subshell with the -x option, which will run the entire script in debug mode. Traces of each command plus its arguments are printed to standard output after the commands have been expanded but before they are executed.
 
eg.
willy:~/scripts> bash -x script1.sh
2.Debugging on part(s) of the script

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

 

阅读(772) | 评论(2) | 转发(0) |
0

上一篇:cygwin下chmod不其作用

下一篇:Bash script(1)

给主人留下些什么吧!~~

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