Is there a better way to run a command N times in bash?

后端 未结 19 2422
执笔经年
执笔经年 2020-11-28 00:26

I occasionally run a bash command line like this:

n=0; while [[ $n -lt 10 ]]; do some_command; n=$((n+1)); done

To run some_command

19条回答
  •  半阙折子戏
    2020-11-28 01:30

    All of the existing answers appear to require bash, and don't work with a standard BSD UNIX /bin/sh (e.g., ksh on OpenBSD).

    The below code should work on any BSD:

    $ echo {1..4}
    {1..4}
    $ seq 4
    sh: seq: not found
    $ for i in $(jot 4); do echo e$i; done
    e1
    e2
    e3
    e4
    $
    

提交回复
热议问题