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

后端 未结 19 2316
执笔经年
执笔经年 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:10

    Using GNU Parallel you can do:

    parallel some_command ::: {1..1000}
    

    If you do not want the number as argument and only run a single job at a time:

    parallel -j1 -N0 some_command ::: {1..1000}
    

    Watch the intro video for a quick introduction: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

    Walk through the tutorial (http://www.gnu.org/software/parallel/parallel_tutorial.html). You command line with love you for it.

提交回复
热议问题