We do not have any goto
statement in bash, hence I used the below function to implement goto
for abrupt jump in the code.
Can we handle this condition without using jumpto
function?
Based on the solution in this earlier answer to a related question I have the following code:
#!/bin/bash
function jumpto
{
label=$1
cmd=$(sed -n "/$label:/{:a;n;p;ba};" $0 | grep -v ':$')
eval "$cmd"
exit
}
start="start"
jumpto $start
start:
while true
do
for <condition>
do
#do something
for <condition>
do
if <condition>
then
break 99
fi
#do something
done
done
done
#do something
#do something
#do manythings
if <condition>
then
#do something
jumpto start
else
#do something
fi
for <condition>
do
#do something
done