A Bourne shell function for repeating a command

This is one of my favorite Bourne shell functions. It lets you repeat any command at a regular interval.

rept () 
{ 
    delay=$1;
    shift;
    while true; do
        eval "$@";
        sleep $delay;
    done
}

For example, if you want to monitor the size of a file as it’s downloading, you can use this to show it every 2 seconds.

rept 2 ls -l bootpage-20040921.zip

Very simple, but super useful.

Leave a Reply

Your email address will not be published. Required fields are marked *