#!/bin/bash
#breakout
while : # : 号为永远为真,且 : 和 while 之间要有空格
do
echo -n "Enter any number[1...5]:"
read ANS
case $ANS in
1|2|3|4|5)
echo "You enter a number between 1 and 5."
;;
*)
echo "Wrong number,bye.."
break
;;
esac
done
#!/bin/bash
#breakout
while :
do
echo -n "Enter any number[1...5]:"
read ANS
case $ANS in
1|2|3|4|5)
echo "You enter a number between 1 and 5."
;;
*)
echo -n "Wrong number, continue(y/n)?:"
read IS_CONTINUE
case $IS_CONTINUE in
y|Y|yes|Yes)
continue
;;
*)
break
;;
esac
esac
done
#!/bin/bash
rm -rf fred*
echo > fred1
echo > fred2
mkdir fred3
echo > fred4
for file in fred*
do
if [ -d "$file" ]; then
break;
fi
done
echo first directory starting fred was $file
rm -rf fred*
exit 0
#!/bin/bash
for x in 1 2 3 4 5 6 7 8
do
echo $x
for y in a b c d e f g
do
echo -n $y
done
echo -e "\\n------------------"
done
[beyes@localhost shell]$ sh for_test_4.sh
1
abcdefg
------------------
2
abcdefg
------------------
3
abcdefg
------------------
4
abcdefg
------------------
5
abcdefg
------------------
6
abcdefg
------------------
7
abcdefg
------------------
8
abcdefg
------------------
#!/bin/bash
for x in 1 2 3 4 5 6 7 8
do
echo $x
for y in a b c d e f g
do
echo -n $y
continue 2 # continue 后,数字1表示在本层循环;2表示上一层循环;以此类推...
done
echo -e "\\n------------------"
done
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |