Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 09-25-2007, 11:59 AM   #1
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76

Rep: Reputation: 16
Question 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:
if condition X exists 
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...
Old 09-25-2007, 01:03 PM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960
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. 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.
Old 09-25-2007, 02:12 PM   #3
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,891

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
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.
Old 09-25-2007, 02:27 PM   #4
LQ Guru
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
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.
Old 09-25-2007, 03:00 PM   #5
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 76
I remember having this conversation before


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
bash-2.05b# Xlib: extension "XFree86-DRI" missing on display ":0.0". citrus Linux - General 8 02-22-2004 10:43 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:41 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration