Paarth
December 25, 2012, 10:58pm
1
Hi ,
I have a code where i am using a infinite while loop . some thing like below
while [ 2 -gt 1 ]
do
if [ logic ]
then
#go to line 20
fi
command 1;
command 2;
#line 20:
sleep 34;
done;
Now i want that if my logic enters the if loop it should go directly to sleep 34 ; and i.e. skip command 1 and command 2 .
Can anyone suggest something .
Yoda
December 25, 2012, 11:07pm
2
There are 2 options:
Call a function that runs sleep
command
sleep_func()
{
sleep 34
}
if [ logic ]
then
sleep_func
fi
Call sleep
inside the if
condition itself:-
if [ logic ]
then
sleep 34
fi
Paarth
December 25, 2012, 11:20pm
3
Hi bipinajith ,
Thanks for yur response but i want to move to line of code of 34 , i am doing a lot of calculations in command 1 and command 2 , I just want to skip these 2 lnes of code and move to line 20 as in my code ...
so above 2 suggestions wont solve my problem , please suggest if you can advice on something which skips command 1 and command 2
Regards
Yoda
December 25, 2012, 11:38pm
4
I don't think there is goto
statement available in most shells except for tcsh
But using it is considered as a bad programming practice.
Why don't you put the commands inside the else
construct of if
statement?
if [ logic ]
then
sleep 34
else
command 1
command 2
fi
1 Like
Paarth
December 25, 2012, 11:54pm
5
Hi ,
Yes , i know its a bad programming practice but i was trying to find it out on bash , may be its not available on bash .
I am sure , if / else will solve this .
Thank You
Paarth
binlib
December 26, 2012, 10:31am
6
if [ logic ]
then
sleep 34
continue
fi