Two difference scenario in bash program,
First
Here i am breaking loop in function testFunc
.
#!/bin/bash
function testFunc {
if [ some condition ] ; then
break
fi
}
while [ 1 ]
do
testFunc
done
Second :
In this case, testFunc
will return some value, and handling the loop from that value.
#!/bin/bash
function testFunc {
FUNC_RET=0
if [ some condition ] ; then
FUNC_RET=1
fi
}
while [ 1 ]
do
testFunc
if [ 0 == $FUNC_RET]; then
break
fi
done
So, which is ideal or proper way to implement this concept.? testFunc
may be written in some other script also.
Hope this is not one of silly questions.
if
and usewhile [ condition ]
...is there a reason? – Bobby Jan 27 at 15:04do...while
loop, so more than one code blocks will be there in loop. andtestFunc
may belong to different script also. – KisHan SarsecHa Gajjar Jan 28 at 5:13