执行命令中的循环

时间:2016-06-28 03:25:07

标签: shell loops

我想在100年内执行120个模型的shell脚本。即。

start=1900; end=2000
using model1,model2, model3 and so on until 120 models

我可以使用以下命令手动执行它们:(比如3个型号)

exec "${script_dir}myscript $start $end $model1 $model2 $model3"

如何使用循环扩展上述命令,如

exec "${script_dir}myscript $start $end $model1 $model2 $model3 $model4 ..... $model120"

1 个答案:

答案 0 :(得分:3)

start=1900
end=2000
command="\${script_dir}myscript \$start \$end"
i=1

while [ $i -le 120 ]
do
    command="$command \$model$i"
    i=`expr $i + 1`
done

exec $command

这个脚本只需执行1到120的for循环,并将所有模型连接到您的命令。

相关问题