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

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

    A little bit naive but this is what I usually remember off the top of my head:

    for i in 1 2 3; do
      some commands
    done
    

    Very similar to @joe-koberg's answer. His is better especially if you need many repetitions, just harder for me to remember other syntax because in last years I'm not using bash a lot. I mean not for scripting at least.

提交回复
热议问题