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
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!
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.
You could use functions in a more or less recursive way. Non-working example using your pseudo-code:
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 "*"
|All times are GMT -5. The time now is 11:27 PM.|