linux sh : bashdb的安装和初步使用
发布日期:2021-06-30 22:17:04
浏览次数:2
分类:技术文章
本文共 3652 字,大约阅读时间需要 12 分钟。
前言
这周在学习linux脚本编程,调试时,用echo 或bash -x
检查语法用bash -n x.sh在函数中,要用echo返回出参字符串,如果再用echo打印调试信息,将逻辑搞乱了。
当时就在想,linux工具这么强大,既然有gdb, 那就有脚本的调试器才对啊.今天在看书时,看到了bashdb这个工具。
在debian下试过了,好使。 虽然没有gdb -tui 那么好使,也满意了。bashdb中也有好多调试命令,进入bashdb后,用help命令可以看到命令列表。
对于脚本的初级调试,掌握几个命令就够用。下载点
实验
# backup /etc/apt/sources.listcp /etc/apt/sources.list /etc/apt/sources.list.bk1# add one row on the file(/etc/apt/sources.list)'s end for install bashdbvi /etc/apt/sources.listdeb http://ftp.de.debian.org/debian wheezy mainwq# update install sourceaptitude update# install bashdbaptitude install bashdb# bash doc# http://www.gnu.org/software/bash/manual/bashref.html# debug linux sh# cd the .sh file dir, debug x.sh by bashdbbashdb $(pwd)/main.sh# bashdb's buildin command listbashdb<0> helpAvailable 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 # list commandbashdb<1> help listlist[>] [LOC|.|-] [NUMBER] LOC is the starting location or dot (.) for current file andline. Subsequent list commands continue from the last linelisted. Frame switching however resets the line to dot. LOC can be aread-in function name or a filename and line number separated by acolon, e.g /etc/profile:5If NUMBER is omitted, use the LISTSIZE setting as a count. Use "setlistsize" to change this setting. If NUMBER is given and is less thanthe starting line, then it is treated as a count. Otherwise it istreated as an ending line number.By default aliases "l>" and "list>" are set to list. In this case andmore generally when the alias ends in ">", rather than center linesaround LOC that will be used as the starting point.Examples:list . # List centered around the curent frame linelist # Same as above if the first time. Else start from where # we last left off.list - # list backwards from where we left off.list> . # list starting from the current frame line.list 10 3 # list 3 lines centered around 10, lines 9-11list> 10 3 # list lines 10-12list 10 13 # list lines 10-13list 10 -5 # list from lines to 5 lines before teh end of the filelist /etc/profile:5 # List centered around line 5 of /etc/profile.list /etc/profile 5 # Same as above.list usage # list centered around function usage().# 列出脚本源码-当前l .# 列出脚本源码-指定行数l 0# bashdb的命令和gdb兼容, 用gdb的命令就可以了# n : 步过# s : 步入# 回车 : 执行上一条命令# 打印变量print $i_indexpr $i_index# 指定行数下断点break 18# 用debian源提供的bashdb下断点有bug, continue后,断不下来# 去官网上下载一个新的bashdb : https://sourceforge.net/projects/bashdb/files/bashdb/4.4-0.94/tar xvf ./bashdb-4.4-0.94.tar.bz2cd bashdb-4.4-0.94/aptitude install autotools-devmake clean./configuremakemake check # 这步有2项通不过,不影响# SKIP: test-file-with-spaces# FAIL: test-sig# SKIP: test-bug-loc# FAIL: test-bug-set-eaptitude remove bashdbrm -rf /usr/share/bashdb/make install# 可以用新版bashdb重新调试脚本了bashdb $(pwd)/main.sh# 列出当前文件所有内容, 行数范围设置大点 从0~1000, 如果这个当前sh只有45行,就都显示全了l 0 1000# 对指定文件的指定行数下断点break /home/dev/main.sh:35# 对函数下断点break func_show_title# 继续 continuec# 断点列表L# 列出指定文件指定行数l /home/dev/common/sh.prog_version:16# 删除断点(指定断点号码, 用L命令看断点列表)delete 1# bashdb好像没有在调试中,设置变量值的控制语法# 执行完一个函数或一个循环finish# 退出调试器q# 好像初步使用bashdb, 查的这些调试命令,已经够用了# 看一本书上,人家调试就用echo 或 bash -x, 人家对脚本编程该有多熟练啊# 如果是我,只有在没有条件的情况下才会用echo, 有利器为啥不用呢?
转载地址:https://lostspeed.blog.csdn.net/article/details/79333713 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月18日 08时39分06秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【转载】将Ubuntu16.04 中gedit在仅显示一个文件时显示文件名tab
2019-04-30
fstream 对象多次使用时注意clear
2019-04-30
调试 LenaCV 3D Camera (Linux)
2019-04-30
OpenCV杂记 - Mat in C++
2019-04-30
lnmp部署
2019-04-30
location区段
2019-04-30
nginx访问控制、基于用户认证、https配置
2019-04-30
用zabbix监控nginx
2019-04-30
SaltStack
2019-04-30
linux内存的寻址方式
2019-04-30
ubunut16.04的pip3出现问题,重新安装pip3
2019-04-30
how2heap-double free
2019-04-30
how2heap-fastbin_dup_consolidate
2019-04-30
orw_shellcode_模板
2019-04-30
[fmt+shellcode]string
2019-04-30
fmt在bss段(neepusec_easy_format)
2019-04-30
python 函数式编程
2019-04-30
python编码
2019-04-30
redis cli
2019-04-30