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

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

    If you are OK doing it periodically, you could run the following command to run it every 1 sec indefinitely. You can put other custom checks in place to run it n number of times.

    watch -n 1 some_command

    If you wish to have visual confirmation of changes, append --differences prior to the ls command.

    According to the OSX man page, there's also

    The --cumulative option makes highlighting "sticky", presenting a running display of all positions that have ever changed. The -t or --no-title option turns off the header showing the interval, command, and current time at the top of the display, as well as the following blank line.

    Linux/Unix man page can be found here

提交回复
热议问题