shell中的for循环

实例1

#!/bin/bash

for((i=1;i<=20;i++));
do
nohup /opt/soft/ngrinder-agent/ngrinder-agent$i/run_agent.sh --agent-home ~/.ngrinde-agent$i --host-id agent$i &
done

 

实例2

#!/bin/bash
 
for i in {1..10}
do
echo $(expr $i \* 3 + 1);
done

 

 实例3

for((i=1;i<=5;i++));

do

for host in {12.160.244.79,12.160.244.81,12.160.245.248,12.160.244.83,12.160.245.249,12.160.244.85,12.160.244.86,12.160.244.88,12.160.244.90,12.160.244.97,12.160.244.7,12.160.245.241,12.160.245.155,12.160.246.129,12.160.245.157,12.160.245.242,12.160.244.72,12.160.246.148,12.160.245.244,12.160.245.245,12.160.245.240,12.160.244.34,12.160.246.100,12.160.244.37,12.160.244.38,12.160.246.101,12.160.244.4,12.160.244.41,12.160.246.109,12.160.244.44,12.160.244.45,12.160.244.249,12.160.244.66,12.160.245.239,12.160.244.68,12.160.244.25,12.160.244.250,12.160.244.254,12.160.244.3,12.160.247.82,12.160.244.32}
do
echo "---------------------" ${host}
curl -X POST -d@'1.txt' http://${host}:9090/cmcc/interface
sleep 1
done

sleep 5

done

 

实例4

 

#!/bin/bash  
  
for i in rootfs usr data data2;  
do  
echo $i is appoint ;  
done 

 

改良版

#!/bin/bash  
  
list="rootfs usr data data2"  
for i in $list;  
do  
echo $i is appoint ;  
done 

 

 

参考文档:https://blog.csdn.net/babyfish13/article/details/52981110

参考文档:https://www.cnblogs.com/EasonJim/p/8315939.html

posted @ 2020-01-16 11:10  豆浆D  阅读(188)  评论(0编辑  收藏  举报