Skip to content

Commit fad87b1

Browse files
authored
Create shift.md
创建文档。
1 parent 91e7ce7 commit fad87b1

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

command/shift.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
shift
2+
===
3+
4+
移动位置参数。
5+
6+
## 概要
7+
8+
```shell
9+
shift [n]
10+
```
11+
12+
## 主要用途
13+
14+
- 将位置参数`$n, $n+1...`重命名为`$1, $2...`
15+
16+
## 参数
17+
18+
n(可选):大于等于1且小于等于参数个数的整数,默认为1。
19+
20+
## 返回值
21+
22+
返回成功除非n大于参数个数或n小于1以及其他非法值。
23+
24+
## 例子
25+
26+
假设我们的脚本文件(test.sh)如下:
27+
28+
```shell
29+
#!/usr/bin/env bash
30+
# 显示前三个位置参数。
31+
echo "$1 $2 $3"
32+
# 移除前两个位置参数,并将$3重命名为$1,之后的以此类推。
33+
shift 2
34+
echo "$1 $2 $3"
35+
```
36+
37+
在终端执行该脚本:
38+
39+
```shell
40+
sh test.sh q w e r t
41+
```
42+
43+
返回信息如下:
44+
45+
```shell
46+
q w e
47+
e r t
48+
```
49+
50+
### 注意
51+
52+
1. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。
53+
54+
55+
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->

0 commit comments

Comments
 (0)