Linux - SoftwareThis 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
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.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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).
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.