I have this code fragment in a bash function:
while ! mkdir lock ; do
inotifywait -t $WAIT_TIMEOUT -e delete_self lock
done
local es=$?
if (( $es != 0 )); then
echo "Checkpoint A"
exit $es
fi
I thought that checkpoint A would be completely unreachable (since a successful mkdir must surely be the last command executed when the while loop terminates).
However, I'm finding that sometimes checkpoint A is reached. How is this possible, even in principle?
From section 2.9.4 of http://pubs.opengroup.org/onlinepubs/9699919799/ regardint the exit status of a while loop:
(Here, "compound-list-2" are the commands inside the
do...done
portion of the while loop.) So the value of$?
will be the result returned the last time inotifywait executed, or zero if it is never called.