Script
[[email protected] shell]# vim for1.sh#!/bin/bashfor i in `seq 1 6`do echo $idone
Execution results
[[email protected] shell]# sh for1.sh123456
Script
[[email protected] shell]# vim for2.sh#!/bin/bashsum=0for i in `seq 1 6`do echo "$sum + $i" sum=$[$sum+$i] echo $sumdone
Execution results
[[email protected] shell]# sh for2.sh0 + 111 + 233 + 366 + 41010 + 51515 + 621
A For loop is a separator that loops with a space or a carriage return as a delimiter.
[[email protected] shell]# mkdir test[[email protected] shell]# cd test[[email protected] test]# touch 1 2[[email protected] test]# touch 3\ 4.txt[[email protected] test]# ls -l总用量 0-rw-r--r-- 1 root root 0 4月 20 08:13 1-rw-r--r-- 1 root root 0 4月 20 08:13 2-rw-r--r-- 1 root root 0 4月 20 08:13 3 4.txt[[email protected] test]# for i in `ls ./ `; do echo $i ; done1234.txt
Shell Programming--for Loops