Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Evaluating the current source line before it runs

rocky edited this page · 2 revisions

I find I sometimes want to run the line that’s about to be executed to see if I want to step into methods that are called.

For example:

(/etc/apparmor/functions:24):
PROFILES="/etc/apparmor.d"
zshdb<2> 

I had been cutting and pasting the command as shown, but realized I could do better if I made a command for this. So that’s what I’ve done.

If you run the eval command without any arguments, it will run the command that is about to be run.

(/etc/apparmor/functions:24):
PROFILES="/etc/apparmor.d"
zshdb<2> eval
eval: PROFILES="/etc/apparmor.d"
$? is 0
zshdb<3> 

This was working fine, until I started coming across tests inside if, elsif, and until blocks. For example:

(/etc/init.d/apparmor:70):
if [ "$1" = "recache" ]
then
	log_daemon_msg "Recaching AppArmor profiles"
 ...

Suppose I want to know which branch I’m going to take before taking the branch. That way I might even be able to change which way to go by changing the test before it runs in the debugged program. (In the above example, I could print $1

zshdb<2> pr $1
status

But I’m lazy. I’d rather let the debugger do the work for me:

zshdb<1> eval?
eval: [ "$1" = "recache" ]
$? is 1

If you alias eval with a name that ends in ? it will strip off any leading if, case, while, elif, or return.

Something went wrong with that request. Please try again.