#!/bin/bash
for_1 () {
echo ' for 1 show item ' for
var in item1 item2 ... itemn do
Echo ${var};
Done
}
for_2 () {
echo ' for 2 show 1~5 ' for
loop in 1 2 3 4 5
do
echo ' The value is: ${loop} '
done
}
for_3 () {
echo "for 3 show string array" for STR in ' This is
a string ' " C17/>do
Echo ${str}
for_4 () {
echo "for 4 show string" for
str in "' This is a string ' This is a number ' ' Does
echo ${str}
for_5 () {
echo "for 5 show ls" for
file I n ' ls./'
do
echo ${file}
for_6 () {
echo ' for 6 show () '
for (i=1;i<=5;i+ +))
do
echo "This is the first $i call";
Done
}
for_1
for_2
for_3
for_4
for_5
for_6
# for use the two types of command for
file in $ (LS); Do Echo ${file}; Done for
file in ' ls ';;d one of Do Echo ${file}
Results:
for 1 show item item1 item2 ... itemn for 2 show 1~5 the value is:1 the value is:2 the value Is:3 the value is:4 the value Is:5 for 3 show string array This is a string this is a number to 4 show string ' This is a string ' "is" a number ' for 5 show LS array.sh for.sh function.sh if.sh op.sh params.sh read.sh string.sh TRAP.S H varaiable_assignment.sh while.sh XAA for 6 show () This is the 1th time call this is the 2nd call this is the 3rd call this is 4th call this is the 5th call array.sh for.sh Fun
ction.sh if.sh op.sh params.sh read.sh string.sh trap.sh varaiable_assignment.sh while.sh xaa array.sh for.sh function.sh if.sh op.sh params.sh read.sh string.sh trap.sh varaiable_assignment.sh while.sh xaa