Results 1 to 7 of 7
I google goto for linux and just get hundreds of unaswered questions. This is basic, no pun intended.
:begining looping bat
loop:
ping google.com >> output.txt
pause 60
goto loop:
...
- 12-30-2010 #1Just Joined!
- Join Date
- Dec 2010
- Posts
- 40
googlinig goto
I google goto for linux and just get hundreds of unaswered questions. This is basic, no pun intended.
:begining looping bat
loop:
ping google.com >> output.txt
pause 60
goto loop:
This is logical. Not only so, but inevitable logic. Which cannot be replaced with sytax. Well, That isn't true. I guess, logic can be overridden with gobbeldygook, as we see in government everyday.
How is this done?
- 12-30-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
I'm not quite sure what you are getting at. In any case, the example you give is a DOS/Windows batch file, not a Linux shell script, though you can pretty much do the same thing in a bash, csh, ksh, sh script as necessary. Yes, goto's are not generally considered good programming practice. Normally they can be replaced with more "standard" loop and break instructions. So, what do you really need to find out?
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 12-30-2010 #3Just Joined!
- Join Date
- Dec 2009
- Location
- Maryland, USA
- Posts
- 83
A very confusing post due either to generational, cultural, or language differences. Or maybe the confusion is chemically induced. Either way, I welcome the short diversion.
You Googled what? It might be helpful to put the exact search phrase in quotes, like "goto" or "goto for linux", but I don't know how relevant it is to your point. As good as Google is at turning coal to diamonds, garbage in still often results in garbage out. Why did you Google that? What point are you trying to make, how was the search supposed to support your thesis, or what results were you expecting?
You say the result of your search was hundreds of unanswered questions. Yes, Google provides many results, but it does not typically provide "unanswered questions." You may have many unanswered questions, but we can't help with those or respond to them until we know what they are. Ask them one at a time, and we'll go from there.
"This is basic . . ." What is basic? The code? As for the code snippet you provided, how does it support your point?
Then you seem to make a point: (I paraphrase) "goto is inevitable logic that can't be replaced by syntax," but then you contradict yourself. Internal conflict?
You leave us thinking with a sharp turn to a political statement from the Montana foothills that makes little sense, posing the profound question, "How is this done?"
Backatcha with, "How is what done?"
- 12-30-2010 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
If you write like this
the lines become a haiku
spring comes, now it's clear
google goto for
linux and just get hundreds
of unaswered quest
:begining looping
bat loop: ping googlecom; out-
put pause goto loop:Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 12-30-2010 #5
- 12-30-2010 #6Just Joined!
- Join Date
- Dec 2010
- Posts
- 40
THE ANSWER:
<<Simple dos>>:
loop:
ping google.com >> output.txt
pause 60
goto loop:
<<linux equal, best I could get>>:
while true; do
ping google.com >> test.txt
done
To me, the dos is self evident and seemingly more powerful. The Unix way, would take an essay to explain, as evidenced by regular "no replies" on many threads to dos users trying to convert.
To me the power of language or OS, is the length of uptake for a new user.
I am not arguing the beauty or power of that thing you call the "bash" (Something named for a party couldn't be that bad.), just the natural logic being thrown out, for a shorter syntax. Yes, I understand goto's are frowned on, but don't bar them, as many times not worth replacing as they are tricky to replace! I like abbrv. just allow me the ability to use the word abbreviate as a newbie. My impression is I would take 2 hours just to get a grip on the goto replacement, "while", while "goto" took 30 seconds to grasp back in 1982 when you had to write your own programs to run a computer. And so, it would take hundreds of hours-- I am guessing here-- to get a basic grasp to even begin converting the dos scripts that took months to write and perfect, but mere hours to learn the syntax. --See clay dos utilities, etc.)
MS word overtook WordPerfect, because of uptake, not inherent power.
I am open to the power and future study, but only if basic uptake were simplified.
- 12-30-2010 #7
First, the straightforward answer to your question:
Bash doesn't support goto. I think most shells on Unix don't. However, tcsh and Perl both have "goto", so if you prefer to use goto, you could use one of them.
tcsh (and C-shell in general) has some limitations you might want to know about if you choose to use it. I never used it much, personally. I guess my current impression of it would be that it's less powerful than bash but with a somewhat nicer syntax. (C-shell's big distinguishing feature is a syntax similar to the C programming language...)
Perl, of course, lets you do pretty much anything you can think of.
Terrifically ugly language IMO, but it's very powerful. Between the two perl is probably the more common these days.
I think this is a poor example. To me, a simple "while" loop like that is plain as day. Keep doing something forever... The "while" loop presents that meaning much more clearly than the "goto" version. But really both are pretty clear because they're so simple... If there were a condition in that loop, a nice feature of the structured approach is that it makes that condition an explicit component of the loop's structure.
A more complex example would change things a bit. There are cases where working strictly within structured programming mechanisms can become cumbersome and a "goto" really can be the most straightforward way to do something... I think using "goto" to get out of a nested loop is much clearer than "break 2" (meaning "break out of two levels of loop"), for instance. But the problem with "goto" generally is that, while it seems simple enough in simple examples, as the code becomes more complex it can be difficult to follow the path of execution. Minimizing the use of goto and building the program using the structured paradigm helps keep sequential instructions sequential in the code.
Of course, speaking for myself here, I think the specific way they chose to handle structured programming syntax in the Bourne Shell and related Unix shells is pretty ridiculous. I mean, "elif", "fi", "done"... all pretty ugly IMO. Then there's the whitespace issue around conditional operators ("if [ true ]" is correct, "if [true]" and "if[true]" are errors), the need for a semicolon or newline between "if" and "then" or "while" and "do", and so on... It's mostly a consequence of the shell not reserving much in the way of syntax for its own needs. It has to use keywords instead. Still, in terms of what you can do with bash vs. what you can do in a batch file... I think batch files' capabilities have improved somewhat since the DOS days but mostly they're a joke. Bash is ugly IMO but it's powerful enough that you can do a lot with it.
Personally I believe in and support the prevalent anti-goto attitudes. I think that in the long run, what you get from structured programming is a better program and a better approach to programming. So, take that for what it's worth... If you are interested in learning to better understand the bash approach, I'm sure we could help you with that. Or you can run perl and tcsh and program in the style you're already used to. Either way works.


Reply With Quote
