The gap built in for bash allows you to do what you do, it just breaks with a negative value and returns $ status? will be 1:
while true do if [ -f "./test" ] ; then break -1 fi done echo $?
Note that this is described in the help for the inline fault:
help break
break: break [n] Exit for, while or while loops.
Exits a FOR, WHILE, or UNTIL loop. If N is indicated, break N by looping.
Exit Status: The exit status is 0 if N is not greater than or equal to 1.
You can break out of n number of cycles or send a negative value for a break with a non-zero return, i.e. 1
I agree with @hagello, as one of the options sleeps and changes the loop:
#!/bin/bash timeout=120 waittime=0 sleepinterval=3 until [[ -f "./test" || ($waittime -eq $timeout) ]] do $(sleep $sleepinterval) waittime=$((waittime + sleepinterval)) echo "waittime is $waittime" done if [ $waittime -lt $sleepinterval ]; then echo "file already exists" elif [ $waittime -lt $timeout ]; then echo "waited between $((waittime-3)) and $waittime seconds for this to finish..." else echo "operation timed out..." fi
source share