Shell Single stepping through a shell script

You set a breakpoint in a script by editing it, inserting read foo where needed.
As for single stepping, I never needed it since set -x is a very nice shell script x-ray machine.
 
I like logger(1) to print debug information which does not spoil STDOUT but show up in one of the log files in /var/log/. This is of course no single step what you have asked for but very useful.

For testing parts of a scrips I do the dumb way and place an exit at the end of the section of interest.
 
Is there any way to single step through a shell script, or even set breakpoints?
I do sort of single stepping by opening the shell script in a text editor in one window and have the terminal open in another window side by side. Then I drag & drop the script line by line into the terminal. The trick is to select and drop the line break as well, so you won't need to switch to the teminal only for pressing return/enter there.
  • If you want exact sh behaviour, then start sh before anything else. In case you use bash, be sure you have "set enable-bracketed-paste off" in .inputrc. Because of it's peculiarities, you don't want to use tcsh for this.

  • This does not work in the console, because you don't have windows which you may arrange and so you can see both at the same time.

  • When your text editor/terminal does not support drag&drop (GNOME's Terminal and gedit does) then you may refrain to copy&paste (it's not as elegant, but works as well).

  • You can do this even from another computer, provided that the Terminal from which you connect via ssh and the editor supports drag&drop.

  • You can select a bunch of commands at once and drag&drop them into the terninal, and this way you would emulate break points.
 
You set a breakpoint in a script by editing it, inserting read foo where needed.
As for single stepping, I never needed it since set -x is a very nice shell script x-ray machine.
It would be nice if, in addition to '-x' there was something like a '-p' for pause after each command in a shell script.
 
I do sort of single stepping by opening the shell script in a text editor in one window and have the terminal open in another window side by side. Then I drag & drop the script line by line into the terminal. The trick is to select and drop the line break as well, so you won't need to switch to the teminal only for pressing return/enter there.
I'm just getting used to emacs but have it handy in providing a means of opening two windows where you can be editing a script in one window and running it in a shell in the other.
 
Back
Top