> For the complete documentation index, see [llms.txt](https://hezhiqiang.gitbook.io/linux/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hezhiqiang.gitbook.io/linux/ming-ling/shift.md).

# shift

移动位置参数。

## 概要

```
shift [n]
```

## 主要用途

* 将位置参数`$n, $n+1...`重命名为`$1, $2...`。

## 参数

n（可选）：大于等于1且小于等于参数个数的整数，默认为1。

## 返回值

返回成功除非n大于参数个数或n小于1以及其他非法值。

## 例子

假设我们的脚本文件（test.sh）如下：

```
#!/usr/bin/env bash
# 显示前三个位置参数。
echo "$1 $2 $3"
# 移除前两个位置参数，并将$3重命名为$1，之后的以此类推。
shift 2
echo "$1 $2 $3"
```

在终端执行该脚本：

```
sh test.sh q w e r t
```

返回信息如下：

```
q w e
e r t
```

### 注意

1. 该命令是bash内建命令，相关的帮助信息请查看`help`命令。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://hezhiqiang.gitbook.io/linux/ming-ling/shift.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
