Chinaunix首页 | 论坛 | 博客
  • 博客访问: 525092
  • 博文数量: 43
  • 博客积分: 10257
  • 博客等级: 上将
  • 技术积分: 480
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-06 02:16
文章分类

全部博文(43)

文章存档

2011年(5)

2010年(12)

2009年(6)

2008年(20)

分类:

2010-06-30 00:24:22

1. 使用seq

cadenwu@cadenwu-laptop:~/Templates/Bash$ cat loop1.sh
#!/bin/bash

# SYNOPSIS
# seq [OPTION]... LAST
# seq [OPTION]... FIRST LAST
# seq [OPTION]... FIRST INCREMENT LAST

# usage: seq LAST
echo "usage: seq LAST"
for i in $(seq 3)
do
    echo "$i"
done
echo

# usage: seq FIRST LAST
echo "usage: seq FIRST LAST"
for i in $(seq 2 5)
do
    echo "$i"
done
echo

# usage: seq FIRST INCREMENT LAST
echo "usage: seq FIRST INCREMENT LAST"
for i in $(seq 4 2 10)
do
    echo "$i"
done
echo



cadenwu@cadenwu-laptop:~/Templates/Bash$ ./loop1.sh
usage: seq LAST
1
2
3

usage: seq FIRST LAST
2
3
4
5

usage: seq FIRST INCREMENT LAST
4
6
8
10




2. 使用loop

cadenwu@cadenwu-laptop:~/Templates/Bash$ cat loop2.sh
#!/bin/bash

for ((i=3; i<=7; i++))
do
    echo "$i"
done



cadenwu@cadenwu-laptop:~/Templates/Bash$ ./loop2.sh
3
4
5
6
7



3. 大括号{..}

cadenwu@cadenwu-laptop:~/Templates/Bash$ cat loop3.sh
#!/bin/bash

for i in {1..5}
do
    echo $i
done
cadenwu@cadenwu-laptop:~/Templates/Bash$ ./loop3.sh
1
2
3
4
5


阅读(1850) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~