for 迴圈 1~100

測試指令 seq

seq 1 100
echo {1..100}

正規for寫法

for ((i=1; i<=100; i++)); do echo $i ; done

使用 seq 與 {a..b}

for i in $(seq 1 100); do echo $i ; done
for i in {1..100}; do echo $i ; done

印出奇數

for i in $(seq 1 2 100); do echo $i ; done

印出偶數

for i in {2..100..2}; do echo $i ; done

Last updated