katty
1
Hi Folks,
I want to implement do while loop in script for following logic
...
....
do
{
function1
function 2
result = function 3
} while(result !=0);
I gone through tutorial site , says
while [ "$*" != "" ]
do
function1
function2
done
----
But I want to repeat only if function 3 fails... Please suggest
All depend on your shell
For bash a simple do/while example look like:
unset i
while (( i++ < 3))
do
echo $i
done
unset i
That is non-standard:
$ while (( i++ < 3))
> do
> echo $i
> done
dash: cannot open 3: No such file
dash: i++: not found
The standard syntax is:
while [ $(( i += 1 )) -le 3 ]
do
echo $i
done
Though that doesn't work in older versions of the standard *BSD shell. To accommodate those, use:
i=1
while [ $i -le 3 ]
do
echo $i
i=$(( $i + 3 ))
done