调试模式下的 Hello World
$ cat hello.sh 
#!/bin/bash 
echo "Hello World"
$ bash -x hello.sh 
+ echo Hello World
Hello World
-x 参数使你可以遍历脚本中的每一行。这里有一个很好的例子:
$ cat hello.sh
#!/bin/bash 
echo "Hello World\n" 
adding_string_to_number="s"
v=$(expr 5 + $adding_string_to_number) 
$ ./hello.sh 
Hello World
expr: non-integer argument
以上提示错误不足以跟踪脚本; 但是,使用以下方法可以更好地了解在脚本中查找错误的位置。
$ bash -x hello.sh 
+ echo Hello World\n
Hello World
+ adding_string_to_number=s
+ expr 5 + s
expr: non-integer argument
+ v=