Skip to content

Different loop in Bash

方法一

#!/bin/bash
for i in `seq 1 10`
do
    #code here
    echo $i
done

方法二

C语言风格

#!/bin/bash
for ((i=1; i<=10; i++))
do
    printf "%s\n" "$i"
done

方法三

#!/bin/bash
i=1
while [ "$i" -lt "10" ]
do
    #code here
    echo $i
    #i=$[ $i + 1 ]
    ((i++))
done

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try my iOS App