Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with goto ,blocks

 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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



 
Doug Slattery
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

executing:

$ . 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.
Aloha,
Doug

-- Nothing is impossible if I'mPossible

[ January 31, 2008: Message edited by: Doug Slattery ]
[ January 31, 2008: Message edited by: Doug Slattery ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic