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

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

    The script file

    bash-3.2$ cat test.sh 
    #!/bin/bash
    
    echo "The argument is  arg: $1"
    
    for ((n=0;n<$1;n++));
    do
      echo "Hi"
    done
    

    and the output below

    bash-3.2$  ./test.sh 3
    The argument is  arg: 3
    Hi
    Hi
    Hi
    bash-3.2$
    

提交回复
热议问题