Menu

Nested Shell

Rocky Bernstein

Although the debugger allows one to evaluate arbitrary bash code using the debugger eval command or the set autoeval mode, sometimes you might prefer to work inside a bash shell to see variables, experiment, issue commands (using the currently-set up environment), and even change variables and functions.

For this we, the debugger shell command, enters a nested shell session. But before it does this, it saves out variable and function definitions in the current context of the running program. That way, you have access to those.

This however creates a new problem: getting changes you make reflected back into the running program. Right now any variable you change can be flagged to have its value re-read when the shell exits. This is done using the save_var function inside the nested shell. save_var takes a list of variable names.

Here is an example session

bashdb /etc/init.d/apparmor status
bashdb debugger, release 0.9

Copyright 2008-2011, 2014 Rocky Bernstein
...
(/etc/init.d/apparmor:35):
. /etc/apparmor/functions
bashdb<1> s
(/etc/apparmor/functions:24):
PROFILES="/etc/apparmor.d"
bashdb<2> s
(/etc/apparmor/functions:25):
PARSER="/sbin/apparmor_parser"
bashdb<3> shell
bashdb $ typeset -p PROFILES
typeset PROFILES=/etc/apparmor.d
bashdb $ PROFILES='Hi, Mom!'
bashdb $ save_vars PROFILES
bashdb $  <EOF>
(/etc/apparmor/functions:25):
PARSER="/sbin/apparmor_parser"
bashdb<4> x PROFILES
typeset PROFILES='Hi, Mom!'
bashdb<5>

Note that inside the nested shell the we have set the prompt has been set to: bashdb $


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.