Linux sh: bashdb installation and preliminary use, shbashdb

Source: Internet
Author: User

Linux sh: bashdb installation and preliminary use, shbashdb
Preface

This week, echo or bash-x is used for linux Script Programming and debugging.
Run bash-n x. sh to check the syntax.

In a function, echo is used to return the output parameter string. If echo is used to print debugging information, the logic is disrupted.
At that time, I was thinking that the linux tool was so powerful that since gdb was available, it would be right to have a script debugger.

Today, I saw the bashdb tool.
I tried it In debian.
Although it is not as good as gdb-tui, it is also satisfied.

Bashdb also has many Debugging commands. After Entering bashdb, run the help command to view the command list.
For the initial debugging of the script, it is enough to master several commands.

Download point

Bashdb-4.4-0.94.tar.bz2.7z

Lab
# 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. 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 abve 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 und 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 abve. list usage # list centered around function usage (). # list script source code-current l. # list the script source code-specify the number of lines l 0 # The bashdb command is compatible with gdb. Use the gdb command # n: Step # s: Step # press Enter: run the previous command # print the variable print $ I _indexpr $ I _index # specify the number of rows under the breakpoint break 18 # There is a bug in the bashdb provided by the debian source. After continue, disconnected # Go to the official website to download a new 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 # There are two items in this step that are not affected # 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 # You can use the new version of bashdb to re-debug the script bashdb $ (pwd)/main. sh # list all contents of the current file. The number of rows ranges from 0 to 0 ~ 1000. If the current sh contains only 45 lines, all of them are displayed. l 0 1000 # breakpoint break/home/dev/main under the specified number of lines of the specified file. sh: 35 # breakpoint break func_show_title # continue continuec # breakpoint list L # list the specified number of lines in a file l/home/dev/common/sh. prog_version: 16 # delete a breakpoint (specify the breakpoint number and use the L command to view the breakpoint list) delete 1 # bashdb does not seem to be under debugging, set the variable value control syntax # execute a function or a loop finish # exit the debugger q # It seems that bashdb is initially used, and these Debugging commands are enough # Read a book, echo or bash-x is used for debugging. How skilled people are in Script Programming. # If it is me, echo is used only when there are no conditions, why not use a powerful tool?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.