REPEAT - repeat a UNIX or LINUX command a specified number of times
By Frank Cox
(Updated on October 26, 2013)
The original version 1.0 of this program was written on May 3, 2013. On October 26, 2013 it was updated to version 2.0 in accord with a suggestion (and patch) submitted by Wladimir Tavares of Cabo Verde. The program now watches to insure that the command being repeated doesn't return an error, such as listing a non-existent directory. If a failure occurs, the program stops repeating the failed command and returns an exit code of -2.
It is sometimes useful to repeat a Linux or Unix command a specified number of times. This can easily be done using a for/do loop with the Bash shell, but some people find that method complex and confusing.
Repeat is very easy, since it only does one thing. You simply tell the repeat command how many times you want it to loop and run the commandline that you feed into it.
Example commandline: repeat 5 echo Hello World
This tells repeat to execute the command "echo Hello World" five times.
Here is the output:
If the command that you are repeating fails, repeat will immediately cease further repetitions of the command, terminate, and return an exit code of -2.
Download and Installation
Repeat is provided as C source code and as a precompiled binary for Centos 6. If you're using a version of Linux or Unix other than Centos 6 you can compile the program by extracting the archive and typing "make" (without the quotes). That will build the program for you, assuming that you have the gcc compiler installed on your computer. Put the executable (named repeat) into a directory on your path such as /usr/local/bin or /home/yourusername/bin and that's all there is to it.
Click here to download repeat-2.0.tar.bz2
Repeat is FREE SOFTWARE.
Copyright © 2013 Frank Cox
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the Melville Theatre nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Other articles written by Frank Cox can be found here.
Frank Cox owns and operates the Melville Theatre in Melville, Saskatchewan, Canada, and has been playing with computers for over 30 years.
This work is licensed under a Creative Commons Attribution-Share Alike 2.5 Canada License.