2

I heard about the bash debugger ( bashdb ) after reading a comment so I thought I should try it out and see if it can help me analyze bash scripts or more generally the execution of commands. There are facilities which can be leveraged independently of any external program but there is the question of convenience and bashdb runs in the shell and can be called directly or with bash --debugger command when properly configured.

So I tried something trivial in a script:

#!/usr/bin/env bash

{ echo 'abc'; echo 'def'; } | cat

Which is just two echo commands in a list uselessly piped into the cat command. Using bashdb scriptname I get:

(/home/user/bin/scriptname:3):
3:  { echo 'abc'; echo 'def'; } | cat
(/home/user/bin/scriptname:3):
3:  { echo 'abc'; echo 'def'; } | cat
bashdb<0> bashdb<(0)> step

So there is a pipe operator and a subshell is created - the parentheses around the 0 are tribute to that. I try to step in right away. A newline is output but I don't get back the debugger prompt... until I press enter again. By that point I have lost the output of what I type in the debugger and performance seems highly degraded. Doing q and pressing enter, I exit the debugger and now my terminal no longer outputs my commands either. Commands get executed but I need to exit a start a new terminal window to regain any command echo. In some cases, both in the tool and after quitting in bash, not only the commands are no longer echoed but the newline following commands is gone too.

So obviously I have very little experience with that sort of software but this seems to be the desired behavior as I get similar results both on Gentoo and Archbang?? So what happened here and what did I step into?

  • I had a similar situation in the context of sending to the background a job without having a controlling terminal with PD-KSH. So somehow in the example here I've triggered a condition where the commands compete for terminal control so many keystrokes are required for each key etc. – user44370 Sep 11 '14 at 9:41
1

What is going on is that the pipe sets output by default is to go to cat, and that includes debugger output. There is --tty option to tell the debugger where to send output, but that's not doing what I expect it to. (To see what value to put after --tty run tty. File this as a bug and I'll look at it when I can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy