前言
这周在学习linux脚本编程,调试时,用echo 或bash -x 检查语法用bash -n x.sh
在函数中,要用echo返回出参字符串,如果再用echo打印调试信息,将逻辑搞乱了。 当时就在想,linux工具这么强大,既然有gdb, 那就有脚本的调试器才对啊.
今天在看书时,看到了bashdb这个工具。 在debian下试过了,好使。 虽然没有gdb -tui 那么好使,也满意了。
bashdb中也有好多调试命令,进入bashdb后,用help命令可以看到命令列表。 对于脚本的初级调试,掌握几个命令就够用。
下载点
bashdb-4.4-0.94.tar.bz2.7z
实验
cp /etc/apt/sources.list /etc/apt/sources.list.bk1
vi /etc/apt/sources.list
deb
http:
//ftp.de.debian.org/debian wheezy main
wq
aptitude update
aptitude install bashdb
bashdb $(pwd)/main.sh
bashdb<
0> help
Available
commands:
action condition edit frame load run source unalias
alias
continue enable handle next search step undisplay
backtrace debug eval help
print set step- untrace
break delete examine history pwd shell step+ up
clear disable
export info quit show tbreak watch
commands display file kill
return signal trace watche
complete down finish list reverse skip tty
bashdb<
1> help list
list[>] [LOC|.|-] [NUMBER]
LOC
is the starting location
or dot (.)
for current file
and
line. Subsequent list commands
continue from the last line
listed. Frame switching however resets the line to dot. LOC can be a
read-
in function name
or a filename
and line number separated
by a
colon, e.g /etc/
profile:
5
If NUMBER
is omitted, use the LISTSIZE setting as a count. Use
"set
listsize" to change
this setting. If NUMBER
is given
and is less than
the starting line,
then it
is treated as a count. Otherwise it
is
treated as an ending line number.
By
default aliases
"l>" and "list>" are set to list. In
this case and
more generally
when the alias ends
in ">", rather than center lines
around LOC that will be used as the starting point.
Examples:
list .
list
list -
list> .
list
10 3
list>
10 3
list
10 13
list
10 -
5
list /etc/
profile:
5
list /etc/profile
5
list usage
l .
l
0
print $i_index
pr $i_index
break 18
tar xvf ./bashdb-
4.4-
0.94.tar.bz2
cd bashdb-
4.4-
0.94/
aptitude install autotools-dev
make clean
./configure
make
make check
aptitude remove bashdb
rm -rf
/usr/share/bashdb/
make install
bashdb $(pwd)/main.sh
l
0 1000
break /home/dev/main.
sh:
35
break func_show_title
c
L
l /home/dev/common/sh.
prog_version:
16
delete 1
finish
q