How can I write a tiny Bash shell script to repeat an action every 5 seconds? How can I write a tiny Bash shell script to repeat an action every 5 seconds? shell shell

How can I write a tiny Bash shell script to repeat an action every 5 seconds?


The watch command is a good option. If you end up needing more control you can use a while loop:

while [ 1 ]do  cp source dest  sleep 5sdone


while truedo    cp file /other/location    sleep 5done

You don't even need to write a script for this, just type while true; do cp file /other/location; sleep 5; done at the bash prompt.


Perhaps watch will do:

watch -n 5 date