Copyright(c) by Galaxy CD – http://www.galaxycd.com
56
toto is not a file
$
ls
-l
/users/user8
total 5
-rw-------
1 phil animator 56 May 31 14:14:22 file1
-rw-------
1 phil animator 22 May 31 15:14:22 file2
11.3.2 Voøng laëp while vaø until
a )
while do done
Voøng laëp while thöïc hieän moät chuoãi leänh khi ñieàu kieän vaãn coøn thoaû maõn.
while command1
do
command2
command3
command4
…………………
done
Khi giaù trò traû veà cuûa vieäc thöïc hieän command1 vaãn thoaû maõn ñieàu kieän (true), shell
thöïc hieän tieáp chuoãi leänh giöõa do … done.
Hai leänh thöôøng duøng trong voøng laëp while:
true
hoaëc
:
cho giaù trò true(0)
sleep[n]
ñôïi n giaây
Thí duï:
-
shell_script param hieån thò taát caû caùc ñoái cuûa leänh.
$
cat param
while test
$#
-ne
0
do
echo $1
shift
done
-
shell_script disp_time hieån thò soá lieäu ngaøy thaùng theo khoaûng thôøi gian 30
giaây.
$
cat disp_time
while true
hoaëc while :
do
date
sleep 30
done
b)
until do done
Voøng laëp until hoaït ñoäng ngöôïc laïi vôùi voøng laëp while
until command1
do
command2
command3
command4
…………………