- 论坛徽章:
- 0
|
在写脚本时。开始会出一些错误。为了排除这些错误,所以我们需要对自己的脚本检测。
系统的检测方法:
检测语法的:(不能检测到逻辑错误。只能检测到语法错误)
[root@localhost shell]# bash -n 2.sh (以bash的命令解释器去检测所有语法)
或者在脚本里写
#!/bin/bash -n
set是对你要检测代码的打印
set -x 是开启 set +x是关闭 set -o是查看 (xtrace),set去追中一段代码的显示情况。
[root@localhost shell]# set -x
++ echo -ne '\033]0;root@localhost:/shell'
[root@localhost shell]# set -o
+ set -o
allexport off
braceexpand on
emacs on
errexit off
errtrace off
functrace off
hashall on
histexpand on
history on
ignoreeof off
interactive-comments on
keyword off
monitor on
noclobber off
noexec off
noglob off
nolog off
notify off
nounset off
onecmd off
physical off
pipefail off
posix off
privileged off
verbose off
vi off
xtrace on (开启)
++ echo -ne '\033]0;root@localhost:/shell'
[root@localhost shell]#
++ echo -ne '\033]0;root@localhost:/shell'
[root@localhost shell]# var=123
+ var=123
++ echo -ne '\033]0;root@localhost:/shell'
[root@localhost shell]# echo $var
+ echo 123
123
++ echo -ne '\033]0;root@localhost:/shell'
[root@localhost shell]# set -x
+ set -x
++ echo -ne '\033]0;root@localhost:/shell'
[root@localhost shell]# set +x
+ set +x
[root@localhost shell]# set -o
allexport off
braceexpand on
emacs on
errexit off
errtrace off
functrace off
hashall on
histexpand on
history on
ignoreeof off
interactive-comments on
keyword off
monitor on
noclobber off
noexec off
noglob off
nolog off
notify off
nounset off
onecmd off
physical off
pipefail off
posix off
privileged off
verbose off
vi off
xtrace off
在脚本里的可以这样写(不过这个是对所有脚本打印),可以在一断代码追踪
#!/bin/bash
set -x
.....
set -x
-----------------------------------------------------------
文章来源:http://www.unixcom.cn/thread-3019-1-1.html |
|