File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Linux / UNIX and the fly likes problem with  goto ,blocks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "problem with  goto ,blocks " Watch "problem with  goto ,blocks " New topic

problem with goto ,blocks

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
Hi we are trying to migrate open VMS script to ksh unix scripts
in open vms we have goto concept which is not possible in ksh shell scripting .
Is there any other alternative fo this?
I got one solution for this but it is not working correctly,here i just replaced the blocks with functions and in place of goto i am using condition check to flow the control to functions in place of blocks.
But here there is a problem with function call, because ksh unix shell script is not not having compiler it runs step by step (interpreter).
so where ever i find blocks i will replace with functions.
I have to declare the function prior to function call otherwise i wont work for the first time.
Even though if i declare the functions first and function calls next it makes the program structure very complex
so my straight question is what will be the best alternative for goto in ksh ?
Thanks very much in advance
Hoping that you will provide me best solution

SCJP 1.4
Doug Slattery
Ranch Hand

Joined: Sep 15, 2007
Posts: 294
Hi Saikrishna,

Shell scripts don't have the notion of goto, but there is a way around it which may seem kludgey. It involves the use of multiple shell scripts, with the goto scripting blocks in each script. Where you would normally execute a script (and it's in your path):

$ myscript


$ . myscript

will run myscript in the current shell and not spawn a new process. So for example, a small script like this:

will mimic something like this:

You will put the block of code for myscript in a shell script named myscript.

That's the first work around that comes to mind.
Hope this helps.

-- Nothing is impossible if I'mPossible

[ January 31, 2008: Message edited by: Doug Slattery ]
[ January 31, 2008: Message edited by: Doug Slattery ]
I agree. Here's the link:
subject: problem with goto ,blocks
It's not a secret anymore!