Bashdb is a debugger for Bash scripts, allowing interactive debugging with features like breakpoints, step execution, variable inspection, and stack tracing. It’s ideal for troubleshooting and analyzing complex scripts.
We will create a docker container that will be used to build bashdb.
FROM fedora:24
RUN dnf -y install rpm-build rpm-devel rpmlint make rpmdevtools
RUN dnf -y install autoconf automake texinfo
RUN dnf -y install wget
$ docker build --progress=plain -t fedora.24 .
$ docker run -it -v /root:/root fedora.24 bash
We will download bashdb source code and build in the docker container.
$ rpmdev-setuptree
$ cd /root/rpmbuild/SOURCES
$ wget --no-check-certificate https://sourceforge.net/projects/bashdb/files/bashdb/4.3-0.91/bashdb-4.3-0.91.tar.gz
/root/rpmbuild/SPECS/bashdb.spec
.
Name: bashdb
Version: 4.3
Release: 0
Summary: bashdb debugger
License: GPLv2+
BuildArch: noarch
Source0: bashdb-4.3-0.91.tar.gz
%description
debugger for bash script
%prep
tar xf /root/rpmbuild/SOURCES/bashdb-4.3-0.91.tar.gz
%build
mkdir -p /opt/bashdb
cd bashdb-4.3-0.91
./configure --prefix=/opt/bashdb
make
%install
cd bashdb-4.3-0.91
make install
mkdir -p %{buildroot}/opt/bashdb
cp -r /opt/bashdb/bin %{buildroot}/opt/bashdb
cp -r /opt/bashdb/share %{buildroot}/opt/bashdb
%files
/opt/bashdb
$ rpmbuild -bb /root/rpmbuild/SPECS/bashdb.spec
$ cp /root/rpmbuild/RPMS/noarch/bashdb-4.3-0.noarch.rpm /root
$ rpm -ivh --nodeps bashdb-4.3-0.noarch.rpm
$ /opt/bashdb/bin/bashdb --help
Start a script under bashdb control.
$ bashdb /usr/bin/ldd
Redirect output to another terminal.
term1$ tty
/dev/pts/1
term0$ bashdb /usr/bin/ldd > /dev/pts/1
Hardcode a breakpoint at a line of code.
source /opt/bashdb/share/bashdb/bashdb-trace -L /opt/bashdb/share/bashdb
_Dbg_debugger
Problem.
bashdb: /usr/bin/bash: bad interpreter: No such file or directory
Solution.
$ ln -s /bin/bash /usr/bin/bash
Solution: Invoke bashdb from the script.
# add the below line to the script
source /opt/bashdb/share/bashdb/bashdb-trace -L /opt/bashdb/share/bashdb
_Dbg_debugger