Linux命令:shift

移动位置参数。

2024-12-31 17:38:42

命令行command

概要

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命令。

评论

静谧以待,您的评论将是点睛之笔

撰写首个评论,启程你的前端奇妙之旅

is a Wiki for programming enthusiasts and professionals, organizing knowledge on programming.

Connect With Me

I have a fair amount of knowledge of Javascript, Typescript, VueJs, and Nuxt. If you have an interesting idea, either open source or paid let's connect.

Sent Mail
© 2024-2025 © . All rights reserved.