Debug Your Shell Scripts With bashdb
Nov 24, 2008, 23:33 (0 Talkback[s])
(Other stories by Ben Martin)
How to Help Your Business Become an AI Early Adopter
"The Ubuntu Intrepid repository contains a package for bashdb,
but there is no special bashdb package in the openSUSE 11 or Fedora
9 repositories. I built from source using version 4.0-0.1 of bashdb
on a 64-bit Fedora 9 machine, using the normal ./configure; make;
sudo make install commands.
"You can start the Bash Debugger using the bash --debugger
foo.sh syntax or the bashdb foo.sh command. The former method is
recommended except in cases where I/O redirection might cause
issues, and it's what I used. You can also use bashdb through ddd
or from an Emacs buffer.
"The syntax for many of the commands in bashdb mimics that of
gdb, the GNU debugger. You can step into functions, use next to
execute the next line without stepping into any functions, generate
a backtrace with bt, exit bashdb with quit or Ctrl-D, and examine a
variable with print $foo. Aside from the prefixing of the variable
with $ at the end of the last sentence, there are some other minor
differences that you'll notice. For instance, pressing Enter on a
blank line in bashdb executes the previous step or next command
instead of whatever the previous command was.