bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bash RFE: Goto (especially for jumping while debugging)


From: Richard Neill
Subject: Bash RFE: Goto (especially for jumping while debugging)
Date: Mon, 22 Sep 2008 20:44:46 +0100
User-agent: Thunderbird 2.0.0.16 (X11/20080725)

Dear All,

Here's a rather controversial request, namely that bash should support 'goto'.

The reason I'd like to see it is to make debugging long scripts easier. I'm working at the moment on a 2000+ line script, and if I want to test stuff at the end, I'd really like to have something like the following:


-------------------
#!/bin/bash

#initialisation stuff goes here.

goto LABEL

#lots of stuff here that I want to skip.
#Bash doesn't have a multi-line comment feature.
#Even if it did, one can't do a multi-line comment containing
#another multi-line comment. A good editor makes this less
#painful, but isn't an ideal solution.

LABEL

#stuff I want to test

exit

#stuff at the end of the script, which I don't want to run while testing.
----------------------


We already have exit, which is really short for "jump directly to the end". What would be great is a way to "jump into the middle".

What do you think?


Richard



P.S. I am sure lots of people will complain (correctly) that "Goto is considered harmful". I'd agree that, in most cases, it is. But in some cases, such as the above, it's quite useful. Maybe the feature could be called "debug-goto" in order to emphasise its debugging nature, as opposed to use in a regular program.


P.P.S. a hack that would demonstrate what I mean could be implemented by abusing heredocs. Instead of
        goto LABEL       ......      LABEL
write
        cat >/dev/null <<'label_foo'         ...     LABEL
This has exactly the same effect.




























reply via email to

[Prev in Thread] Current Thread [Next in Thread]