gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
shell 脚本运行100次命令
- User
shell 脚本运行100次命令
- Assistant
你想用 shell 脚本运行某个命令 100 次,可以用
for循环来实现。下面是一个简单示例:bash#!/bin/bash for i in {1..100} do your_command_here done把
your_command_here替换成你需要运行的命令即可。例子:
bash#!/bin/bash for i in {1..100} do echo "这是第 $i 次执行" done如果你想每次运行的命令带上当前的序号,也可以用
$i来表示。
如果你使用的是比较老的 shell,或者
{1..100}语法不支持,可以这样写:bash#!/bin/bash i=1 while [ $i -le 100 ] do your_command_here i=$((i+1)) done这两种方法都可以达到重复执行命令 100 次的目的。