Is it possible to do do; condition; while
loop in bash
?
For example:
do
curl -f google.com/demo
while [ $? -ne 0 ]
done
If I do
while [ $? -ne 0 ]
do curl -f google.com/demo
done
...I depend on the command before the loop.
No, it's not possible.
The only valid alternative is to use break in an endless loop:
while :; do
if ! curl -f google.com/demo
then
break
fi
done
And anyway this looks like XY question and what you really want maybe is to loop until the command returns nonzero:
while ! curl -f google.com/demo; do :; done
or
until curl -f google.com/demo; do :; done