LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-04-2004, 01:16 PM   #1
terry.trent
Member
 
Registered: Oct 2003
Location: Virginia
Distribution: SUSE, Feather, Red Hat 9
Posts: 53

Rep: Reputation: 15
goto/label command for scripting in bash shell


i am writing a program for a class, and i've run into a road blcok. i'm told that there is a goto/label command for bash shell scripting, but i've yet been able to find it.

i know that it's not proper to use goto and label commands when writing programs, because of the danger newbiness of it, but this is something i need to be able to do if i'm going to write this program.

this is what i'd like to do basically:
line # command

1: echo something
2: echo something else
3: read else
4: else=$else
5: if [ $else=yes ]
6: then echo ok
7: elif [ $else=no ]
8: then goto line 1 (this would be where i would have the goto thingy)


could anyone help me with this? i'm still fairly new to linux/unix and scripting, but i'd like to get this working.

if i can't do this, there is another way to make the program work-i just don't want to go that route because it'd take longer, as well as take more effort (in my opinoin).

thanks in advance!
 
Old 04-04-2004, 04:18 PM   #2
AutOPSY
Member
 
Registered: Mar 2004
Location: US
Distribution: Redhat 9 - Linux 2.6.3
Posts: 836

Rep: Reputation: 31
thsi is a simple shell script, if you want to re return to the beginning, after all your if, else, and elif statements

have a then statemnet that re3executes the script , done.

I do not know of a way to return to the begginning except a more complex else/if blocks.
 
Old 04-04-2004, 04:37 PM   #3
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 57
You could use functions in a more or less recursive way. Non-working example using your pseudo-code:
Code:
do_the_thing () {
    echo something
    echo something else
    read else
    else=$else
    if [ $else=yes ]
    then echo ok
    elif [ $else=no ]
    then do_the_thing
}
do_the_thing             # call the function above
Above the do_the_thing function does whatever it is you're doing and it is called at the bottom of the script so it will launch right away as soon as you launch it. It will call itself recursively until the elif at the end of the function doesn't return true.
 
Old 07-09-2010, 10:15 AM   #4
fnds
LQ Newbie
 
Registered: Jul 2010
Posts: 1

Rep: Reputation: 0
In order to do what you want, put the code inside a loop and use the "break" command to stop, and the "continue" command to jump back to the beginning.

I modified your pseudo code below and added the shell constructs. The changed lines are marked with a "*"
Code:
while true
do
   1: echo something
   2: echo something else
   3: read else
   4: else=$else
   5: if [ $else=yes ]
  *6: then echo ok; break
   7: elif [ $else=no ]
  *8: then continue
done
 
  


Reply


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 shell scripting Sco Linux - Newbie 1 11-09-2004 11:58 AM
Help with I/O on bash shell scripting Dave6383 Programming 1 06-03-2004 05:24 PM
some bash shell scripting eltongeoff Linux - Newbie 2 10-22-2003 01:10 PM
Bash Shell Scripting Help Tangerine Programming 6 05-06-2003 02:10 PM
BASH Shell scripting help ewarmour Linux - General 8 05-25-2002 07:10 AM


All times are GMT -5. The time now is 12:40 PM.

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