Nested Shell

rocky edited this page Mar 16, 2011 · 6 revisions

Although the debugger allows one to evaluate arbitrary zsh code using the debugger eval command or the set autoeval mode, sometimes you might prefer to work inside a zsh 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

zshdb /etc/init.d/apparmor status
zshdb debugger, release 0.07

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

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