# seq: 生成序列

`seq`命令用于生成一个序列，从*FIRST*开始以*INCREMENT*为间隔到*LAST*。`seq`命令在shell脚本中的for循环中很有用。

## 1. 命令格式

```
seq [OPTION]... LAST
seq [OPTION]... FIRST LAST
seq [OPTION]... FIRST INCREMENT LAST
```

## 2. 参数

| 参数                       | 含义           |
| ------------------------ | ------------ |
| -f, --format=*FORMAT*    | 打印的格式        |
| -s, --separator=*STRING* | 分隔符，默认换行     |
| -w, --equal-width        | 生成等长的序列，用0填充 |

## 3. 使用示例

### **实例1：生成1到10的序列**

```
seq 1 5
seq 5
```

结果：

```
1
2
3
4
5
```

如果初始值是1，那么可以忽略，`seq`的*FIRST*默认就是1。

### **实例2：生成1到10的偶数序列**

```
seq 2 2 10
```

结果：

```
2
4
6
8
10
```

### **实例3：小数步长**

```
seq 1 0.5 2
```

结果：

```
1.0
1.5
2.0
```

步长默认是1，不过也可以设置成其它值。

### **实例4：对LAST的处理**

```
seq 3 7 30
```

结果：

```
3
10
17
24
```

序列最后一个值小于等于*LAST*。

### **实例5：格式化输出**

```
seq -f "GFG%02g" 4
```

结果：

```
GFG01
GFG02
GFG03
GFG04
```

### **实例6：分隔符**

```
seq -s " " 10        // 1 2 3 4 5 6 7 8 9 10
seq -s " " 5 10      // 5 6 7 8 9 10
seq -s "-" 5 4 15    // 5-9-13
```

### **实例7：等长输出**

```
seq -w 10
```

结果：

```
01
02
03
04
05
06
07
08
09
10
```

```
seq -w 99 101
```

结果：

```
099
100
101
```

```
seq -w 1 10 50
```

结果：

```
01
11
21
31
41
```

### **实例8：在for中使用**

```
for i in `seq 10`
do
    echo $i
done
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://valineliu.gitbook.io/deuterium-wiki/linux/cmd/seq-sheng-cheng-xu-lie.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
