Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-25-2007, 11:59 AM
|
#1
|
Member
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76
Rep:
|
Bash scripting "skip to"?
I grew up with ancient Commodore64 BASIC and really miss the GOTO command. Is there anything similar in BASH?
For instance, in a bash script, is there a way to tell it to:
Code:
if condition X exists
then
skip to point Y within this script and continue working from that point
And incidentally, is there a more appropriate Forum for non-bug-report questions about BASH and other programs typically included in major Linux distributions? Most of the questions in "Linux - Software" seem a bit heavier than what I've been asking about...
|
|
|
09-25-2007, 01:03 PM
|
#2
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
I'm not a programmer, but from what I've read, GOTO's are generally considered poor programming these days, and should be avoided whenever possible.
A better option, as I understand it, is to set up shell functions that you can import into the 'if' loops as needed. linuxcommand.org has an easy-to-understand explanation of them here and here.
As for bash-related questions, I've generally gotten the best advice simply from the general linux forum. There's also the programming forum, which I guess might be better for advanced scripting questions. The forums all have clear descriptions listed, so simply choose the one that sounds like it best matches your question. If you're wrong, the moderators will simply move it to where it should be.
Last edited by David the H.; 09-25-2007 at 01:15 PM.
|
|
|
09-25-2007, 02:12 PM
|
#3
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
I think the 'case' construct is what you need. In the use of case, you test for a condition, then code the action to take if that condition exists.
|
|
|
09-25-2007, 02:27 PM
|
#4
|
LQ Guru
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131
Rep: 
|
Quote:
I'm not a programmer, but from what I've read, GOTO's are generally considered poor programming these days, and should be avoided whenever possible.
|
This is mostly true, but there are some situations where 'goto' really comes in handy. It's "problem" is that it often causes the code to be difficult to understand because of sudden jumps..however in right places it's a handy tool, and since it can be used to ease things up (with well designed code, of course), learning to use it shouldn't be avoided. I tend to think it's a way of programming that shouldn't be used right from the beginning, but after one has learned more and knows "the way around". In most places a "goto structure" can be replaced with other means, like 'case' for example, but that's still not a reason to completely abandon it.
|
|
|
09-25-2007, 03:00 PM
|
#5
|
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450
Rep:
|
I remember having this conversation before…
|
|
|
All times are GMT -5. The time now is 06:26 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|