Copyright(c) by Galaxy CD – http://www.galaxycd.com
58
do
>file$count
count=expr $count+1
done
$
cat create_file2
integer count=1
while let “count <””10”
do >file$count
count=count+1
done
11.3.3 Ra khoûi moät voøng laëp:
Leänh
break
cho pheùp ra khoûi caùc voøng laëp for, while, until.
Thí duï:
shell_script stock ghi caùc doøng kyù töï vaøo töø baøn phím leân file lines cho tôùi khi
ta goõ töø “END”:
$
cat stock
while true
do
echo “Enter your line:”
read answer
if
test “$answer” = “END”
then break
else echo $answer
>>
lines
fi
done
Chuù yù:
break[n]
cho pheùp ra khoûi n möùc cuûa caùc voøng laëp loàng.
11.3.4 Boû qua phaàn tieáp theo trong moät voøng laëp:
Leänh
continue
cho pheùp boû qua caùc leänh coøn laïi, quay veà ñaàu voøng laëp.
Thí duï:
shell_script supprim xoaù taát caû caùc file coù trong danh saùch ñoái, tröø file save vaø
source:
$
cat supprim
set
-x
for
i
do
if
test
“$i” = “save” -o “$i” = “source”
then continue
fi
echo $i
rm
$i
done
$
cd
appli
$
lc
titi
save source toto