循环体
1. for...do...done(固定循环)
for var in list do commands done
1. 示例1
#!/bin/bash for animal in dog cat elephant do echo "There are ${animal}s.." done
1 #!/bin/bash 2 for animal in dog cat elephant 3 do 4 echo "There are ${animal}s.." 5 done
1 #!/bin/bash 2 for((i = 0; i < 5; ++i)) 3 do 4 echo "this is test!" 5 done
产生十个随机数字
方法1:
#!/bin/bash for i in $(seq 10); do echo "$i: $RANDOM"; done
#!/bin/bash for i in $(seq 10); do echo "$i: $RANDOM"; done
方法2:
1 #!/bin/bash 2 for((i = 0; i < 5; ++i)) 3 do 4 echo "this is test!" 5 done