Reputation: 439
I am trying to using system time in bash to run a few commands.
Here's a simplified version that I tried
echo $(date +%s); while [ $(($(date +%s)+10)) -gt $(date +%s) ]; do echo $(date +%s); done
Upvotes: 0
Views: 350
Reputation: 117298
You check if the current time + 10 seconds is greater than the current time in your loop. That will always be true. It's the same as doing while (( (X+10) > X ))
You could instead calculate the endtime before starting the loop and use that in your comparison:
starttime=$(date +%s)
(( endtime = starttime + 10 ))
echo "$starttime - $endtime"
while (( endtime > $(date +%s) )); do
date +%s
done
Upvotes: 4