Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to do goto in ksh???Help!!!!

Status
Not open for further replies.

suhaimi

Technical User
Aug 3, 2001
71
US
Hi!
Is there any function like goto in ksh???
In C-shell we can use goto:
#!/bin/csh
test:
echo "whatever"
goto test

How do we jump to previous line in KSH??? Please help!

Thanks,
Suhaimi
 
Hi:

While csh supports goto, I don't think either sh or ksh do.

Regards,

Ed
 
Don't use goto. Goto bad.

Use subroutines.

Code:
#!/bin/ksh

somecommands() {
    echo "print something"
    grep grepforsomething filename
}

#now you can run that as a command
somecommands
#end
--
Andy
 
"Don't use goto. Goto bad...."

I don't agree, and I think many other experienced
programmers don't agree. There are some situations where a clean label jump is much preferable to munging an fopen()
call,pattern search and command reevaluation with some
shell utility in a shell function.
Goto is just a tool. More flexible and easily abused than continue and break but in the same class.

 
marsd,
if you're gonna keep misbehaving, I'll have to report you to jamisar. Next thing you know you'll suggest programming in C-sh.

Bad, bad, BAD marsd! vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi naChoZ,
There are certain things that you can not use subroutine and the only way is to use goto.

Suhaimi
 
marsd, vlad
you are both rigth, i sure don't like 'goto' but
there are situations (in every language) a
goto is the (best||) only way.
- if i test a prog and will skip xthousend lines.
- in a switch the 'goto' is allways better readable
as a cascade of 'if-else if-else'.

have a nice xmas
:)
PS: ON-THE-CMD-LINE 'csh' is the best for me!
PPS: i use 'goto' in my progs, once a year.
-----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top