eq1,打印数字1 2 3 4
- for i in 1 2 3 4
- for i in {1,2,3,4}
- for i in {1..4}
- for i in `seq 1 4`
- for i in $(seq 4)
- do
- echo $i
- done
1
2
3
4
eq2,扫描本地文件夹
- for i in $(ls /*)
- do
- echo $i
- done
eq1,打印数字1 2 3 4
- for ((i=0;i<=4;i++))
- do
- echo $i
- done
eq1,打印数字1 2 3 4
- i=1
- while [ $i -le 4 ]
- do
- echo $i
- let i++
- done
eq2,无限循环
- while true
- do
- sleep 1
- done
eq1,当满足条件i=3,则中断本次循环
- for i in $(seq 10)
- do
- [ $i -eq 3 ] && break
- echo $i
- done
1
2
四、continue当条件满足,则跳过本次循环
eq1,当满足条件i=3,则跳过本次循环,3不打印
- for i in $(seq 10)
- do
- [ $i -eq 3 ] && continue
- echo $i
- done
1
2
4
五、exit当条件满足,则退出本次脚本。后面其他命令不再执行
eq1,当满足条件i=3,则退出本次脚本,后面echo "hello"不再执行
- for i in $(seq 10)
- do
- [ $i -eq 3 ] && exit 0
- echo $i
- done
- echo "hello"
1
2