Repeat Command

Home » CentOS » Repeat Command
CentOS 22 Comments

There is a unix command called repeat.

repeat 10 some_command

Basically repeats some command ten times. Is it available on CentOS 6
and what package provides it?

22 thoughts on - Repeat Command

  • I was going to post the same information about finding out with “yum whatprovides”. FWIW, repeat is a built-in command in tcsh. Maybe that’s where you’ve seen it before.

    Alfred

  • I’m even more old-school with bourne syntax:
    i=0
    while [ $i -lt 10 ]
    do echo $i i=expr `$i + 1`
    done

    Just replace the ‘echo $i’ whit whatever command you want – or add it on the next line so you can see the iteration count too.

  • No. But you can do it with ‘seq’:

    for x in $(seq 1 10); do dig @server-ip-address +short +tries=1 +time=1 your-zone.com a; done

    John

  • True. Thing I like about seq is that it also takes an optional increment value which can be very handy at times.

    John

  • I believe OSX has jot, which is what I used to use with FreeBSD. Fairly similar, and OSX does use bash so the expansion ought to work. Don’t have a MAC or BSD box to test right now.


    Scott Robbins PGP keyID EB3467D6
    ( 1B48 077D 66F6 9DB0 FDC2 A409 FA54 EB34 67D6 )
    gpg –keyserver pgp.mit.edu –recv-keys EB3467D6

  • C6’s bash supports this; C5 sadly does not. But thank you for pointing this out to me as I was unaware of this form.

    John

  • Is it _really_ that hard to type the explicit loop with test ([) and expr? These were builtins even in bourne shell eons ago.

  • Les Mikesell wrote:

    It is not hard. I *tested* what I posted yesterday, and copied and pasted it into my email.

    mark

  • Sure it worked on the box where you tested it, but I think your version was at least bash-specific and something you’d need to know which version runs where if you use bourne shells anywhere. I’m not good at tracking that stuff, so I like backwards and cross-platform compatibility.

  • Yes, if you think that downloading/installing/maintaining yet another specialized program on every device that might need it is simpler than typing a couple of lines re-using knowledge that’s been good for 20+
    years.

  • Found this on the web somewhere:

    #!/bin/sh i=0
    num=$1
    shift while [ $(( i += 1 )) -le $num ]; do
    eval “$@”
    done

    Worked fine. Thanks.

  • Someone has already mentioned tcsh, but this is also a builtin
    (syntactic operator like “while” or “for”, actually) in zsh.

    repeat 10 simple_command repeat 10 do list; of; commands; done repeat 10 { list; of; commands }

LEAVE A COMMENT