• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with goto ,blocks

 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic