这是有声音的视频,请检查播放器或者声音输出设备。

这次的学习内容: for循环 和 while循环

//============================================
#!/bin/bash

for a in `seq 1 2 10`
do
echo $a
done

a初始值为1, 然后 a=a+2的操作, 一直到 a<=10
---------------------
for((i=1;i<=10;i=i+2))
do
echo $i
done

for((i=1;i<=10;i++))

[17rumen@localhost ~]$ ./my_07.sh
1
3
5
7
9

//===============================================
统计文件数目
#!/bin/bash

i=0
for name1 in `ls /etc`
do
echo $name1
i=`expr $i + 1`
done

echo $i

//==============================================
#!/bin/bash

a=0

while [ $a -le 10 ]
do
((a=a+1))

if [ $a -eq 5 ]
then
continue
elif [ $a -eq 8 ]
then
break
fi

echo $a
done
-------------------
[17rumen@localhost ~]$ ./my_07.sh
1
2
3
4
6
7

//==========================================
下面是一个录入客户资料的shell脚本

#!/bin/bash

while true
do
echo "登记客户资料(c继续,q退出):"
read choice

case $choice in
c)
echo "请输入客户名字:"
read name1
echo "请输入客户年龄:"
read age1
echo "姓名:"${name1}" - 年龄:"${age1} >>customer.txt
;;
q)
exit
;;
esac
done

--------------------
>> 和 > 区别

>>customer.txt 追加保存到customer.txt文件中, 如果文件不存在会自动创建。

>customer.txt 就会重新写入, 覆盖原有的数据

视频到这里结束 , 88


“linux_shell脚本编程_07 循环语句的学习(for和while)”有5个评论

  1. 08月 7th, 2010 at 23:55:41 #匿名

    怎么不出视频了

    [回复]

    adminreply on 2010-08-08 00:31:01:

    shell视频学习已经完毕了,以后的学习需要自己去摸索。或者以后我遇到一些经典的脚本,会和大家分享。目前就告一段落了,实在抱歉。

  2. 08月 10th, 2010 at 10:53:31 #

    还是很感谢你,对我们入门很有帮助,希望楼主继续发布视频

    [回复]

  3. 07月 15th, 2011 at 16:57:50 #threefloor

    我想问问怎么用Putty连接虚拟机中的linux系统,也就是虚拟机的联网方式设置成什么模式呢?还有就是还用改linux系统的ip吗?

    [回复]

  4. 11月 21st, 2011 at 17:50:59 #匿名

    这个教程对初学者太给力了,感谢老师,感谢祖宗18代

    [回复]

有任何疑问或建议,可以给作者留言:



公告:

  • 2010年5月之前的视频是文字解说演示,没有声音。
  • 2010年5月以后的视频全部带声音。