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

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

    xargs and seq will help

    function __run_times { seq 1 $1| { shift; xargs -i -- "$@"; } }
    

    the view :

    abon@abon:~$ __run_times 3  echo hello world
    hello world
    hello world
    hello world
    

提交回复
热议问题