Hi there,
How do I repeat something for example every 2 seconds? Let's say I'd want to echo 'lol' every two seconds, how should I do that? Thanks!
Hi there,
How do I repeat something for example every 2 seconds? Let's say I'd want to echo 'lol' every two seconds, how should I do that? Thanks!
You only know one thing for sure.
man sleep
Thanks a bunch.
I've got a lot of PHP experience, but bash is all new to me
You only know one thing for sure.
Also, how you do do something equivalent to this?
Increase a numeric variable by one each time the loop runs.Code:do blabla $variable++; done
You only know one thing for sure.
Here is one way:
Code:let x=0 while [ "true" ] do echo "lol($x)" let ++x sleep 1 done
I have a very similar question... Is there a way to do this without the sleep function?
I'm pretty much looking for this converted to code: 'if it has been 2 seconds'
Any help would be greatly appreciated =)
Last edited by ninja23; November 5th, 2008 at 01:25 PM.
the only way I can think of is using date +%S to get the current second. If you create a loop that constantly does date +%S and compared it to the last baselined second, you would find 2 seconds... I think that is unnecessary processing though...
Code:sec=`date +%S` while [1]; do sec1=`date +%S` (( amt_slept = $sec - $sec1 )) if [ $amt_slept -eq 2 ]; then <EXECUTE CODE> sec=`date +%S` fi done
Bookmarks