Bash RFE: Goto (especially for jumping while debugging)
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.
Re: Bash RFE: Goto (especially for jumping while debugging)
On Mon, 2008-09-22 at 20:44 +0100, Richard Neill wrote: How about... --- #!/bin/bash #initialisation stuff goes here. if false; then #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. fi #stuff I want to test exit #stuff at the end of the script, which I don't want to run while testing. -- b. signature.asc Description: This is a digitally signed message part
Re: Bash RFE: Goto (especially for jumping while debugging)
Richard Neill wrote: Dear All, In the future please start a new message for a new thread of discussion. When you reply to old messages from three months ago those of us who actually keep months worth of email see the message threaded with the previous discussion about variables and subshells. If anyone has killed that thread then the continuation is also killed. Here's a rather controversial request, namely that bash should support 'goto'. Although goto does have uses it is definitely a keyword of the damned. cat /dev/null 'label_foo' ... LABEL This has exactly the same effect. I actually was going to reply and suggest exactly the above. But then realized you had already suggested it. Normally I would do a commented out section. Easy and non-controversial. Or I would do if false; then...fi For just a comment section this doesn't seem to be a compelling need. For that you would need to show how writing state-machines or something is so much easier or some such... Since there are other possibilities I would vote to maintain the status quo. Bob