1. For…do…done(固定循环)
2. #!/bin/bash
3. #Program:
4. # testthe for
5.
6. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
7. export PATH
8.
9. #output three animal
10. for animal in dog cat elephant #以不同的变量,填入animal中
11. do
12. #echo "There are $(animal)s..."
13. echo "there are $animal"
14. done
15.
16. #output all the username
17. users=$(cut -d ':' -f1 /etc/passwd)#get the name
18. for username in $users
19. do
20. id $username
21. finger $username
22. Done
23. 使用for,对于数值的控制
24. 简写:
25. s=0
26. For( ( i=1; i<=$nu; i=i+1) )
27. Do
28. S=$(($s+$i))
29. Done
30. Sh的命令参数,可以用于调试脚本
31. Sh –n ….sh 仅仅检查语法错误
32. Sh –v 在执行前,先将script内容显示到屏幕上
33. Sh –x 将使用到的script 内容显示到屏幕上。用于调试很有用