shell bashdb debug

我是ubuntu的系统首先通过sudo apt install bashdb 按照bashdb
然后通过sudo bashdb --debug sh2 来调试sh2 这个shell脚本
下面是实际运行的结果

tao@tao-ThinkCentre-M8600t-N000:~$ sudo bashdb --debug sh2
bash debugger, bashdb, release 4.3-0.91

Copyright 2002, 2003, 2004, 2006-2012, 2014 Rocky Bernstein
This is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.

(/home/tao/sh2:3):
3:    thisString="Hisilicon D05 UEFI 16.12 Release" # 源字符串
bashdb<0> print $thisString

bashdb<1> n
(/home/tao/sh2:4):
4:    searchString="D05" # 搜索字符串
bashdb<2> print $thisString
Hisilicon D05 UEFI 16.12 Release
bashdb<2> l
  1:    
  2:    #!/bin/sh
  3: => thisString="D05 UEFI 16.12 Release" # 源字符串
  4:    searchString="D05" # 搜索字符串
  5:    case $thisString in
  6:      *"$searchString"*) echo Enemy Spot ;;
  7:      *) echo nope ;;
  8:    esac
  9:    
bashdb<3> b 5
Breakpoint 1 set in file /home/tao/sh2, line 5
bashdb<4> c
Breakpoint 1 hit (1 times).
(/home/tao/sh2:5):
5:    case $thisString in

最常用的命令是:
n:表示单步执行
print :用来打印当前变量,省去了原来用echo显示变量内容的步奏
l:列出未来10行要执行的内容
b:断点
c :继续运行到断点出。



bashdb的其他命令如下:
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   

Readline command line editing (emacs/vi mode) is available.
Type "help" followed by command name for full documentation.

可以通过help 命令查询每个命令详细的说明
bashdb<1> help show
show alias       -- Show list of aliases currently in effect.
show annotate    -- Show annotation_level
show args        -- Show argument list to give program on restart.
show autoeval    -- Show if we evaluate unrecognized commands.
show autolist    -- Run list before command loop?
show basename    -- Show if we are are to show short or long filenames.
show commands    -- commands [+|n] -- Show the history of commands you typed.
You can supply a command number to start with, or a + to start after
the previous command number shown. A negative number indicates the
number of lines to list.
show copying     -- Conditions for redistributing copies of debugger.
show debug       -- Show if we are set to debug the debugger.
show different   -- Show if debugger stops at a different line.
show directories -- Show file directories searched for listing source.
show editing     -- Show editing of command lines and edit style.
show highlight   -- Show if we syntax highlight source listings.
show history     -- Show if we are recording command history.
show listsize    -- Show number of source lines debugger will list by default.
show prompt      -- Show debugger prompt.
show warranty    -- Various kinds of warranty you do not have.
show width       -- maximum width of a line.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
通过查看文档和自己的测试,bashdb-4.2.0-7 和centos7的bash-4.2.46版本匹配,并且编译顺利. 使用方法: 解压bashdb [root]#tar xf bashdb-4.2-0.7.tar.gz -C /usr/src 编译安装bashdb 编译安装bashdb有两种方法,区别可以看bashdb的帮助信息. 第一种编译方法: 不结合bash源代码编译和安装bashdb [root]#cd /usr/src [root]#cd bashdb-4.2.0-7 [root]#touch $HOME/missing [root]#touch libtoolT [root]#./configure --prefix=$HOME [root]#make [root]#make install 第二种编译方法: 结合bash源代码编译和安装bashdb 需要准备bash源代码 a).下载bash-4.2.46的src.rpm bash-4.2.46-20.el7_2.src.rpm http://vault.centos.org/7.3.1611/os/Source/SPackages/ b). 提取bash-4.2.46-20源代码 [root]#rpm -ivh bash-4.2.46-20.el7_2.src.rpm [root]#cd $HOME/rpmbuild/SPECS [root]#rpmbuild -bp bash.spec 此时,源代码已经安装到了$HOME/rpmbuild/BUILD目录 c).移动bash的源代码到/usr/src [root]#cd $HOME/rpmbuild/BUILD [root]#mv bash-4.2 bash-4.2.46-20 [root]#mv bash-4.2.46-20 /usr/src d). 准备bash的源码环境 [root]#cd /usr/src [root]#cd bash-4.2.46-20 [root]#./configure && make e). 结合bash编译安装bashdb [root]#cd /usr/src [root]#cd bashdb-4.2.0-7 [root]#touch $HOME/missing [root]#touch libtoolT [root]#./configure --prefix=$HOME --with-bash-src=/usr/src/bash-4.2.46-20 [root]#make [root]#make install 3. 配置bashdb [root]#vi ~/.bash_profile 在最后添加 MANPATH=$HOME/share/man:$MANPATH export MANPATH INFOPATH=$HOME/share/info export INFOPATH [root]#. ~/.bash_profile 设置inc文件路径.[重要.] [root]#mkdir /usr/share/bashdb/ [root]#ln -s ~/share/bashdb/bashdb-main.inc /usr/share/bashdb/ 4.使用bashdb [root]#bash --debugger yourscript.sh var1 var2

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值