linux - shell中如何获取最后一个参数

标签 linux bash shell scripting

我想知道如何获取传递给 bash 函数的最后一个参数,如下所示:

#!/bin/bash

function hello() {
    all=$@         # all arguments
    n=$#           # number of arguments
    first_arg=$1   # argument one
    last_arg= ???  # How to get the last argument?
}

如何设置$last_arg传递给函数的最后一个参数的值?

最佳答案

如果 all 包含 $@,则最后一个参数为 ${all[*]: -1}

关于linux - shell中如何获取最后一个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30780545/

相关文章:

c# - 在 C# 和 .Net Core 中设置鼠标位置

linux - grep 不显示从文件中读取 id 的结果

string - 庆典 : Bad Substitution

linux - 使用超时命令时如何获取文件中的日志?

linux - 将文件中的多个参数传递给 Shell 中的 while 循环

linux - 查找出现 2 个给定单词的文件,并显示出现单词的行

linux - 有没有办法监控/记录来自 Flash/AC3 应用程序的所有互联网请求?

c - Linux 编译简单的程序以在 x86 和 x64 上运行

macos - 在 bash 中, "for;do echo;done"在空格处拆分行

php - 我应该将所有图像放在同一个目录中吗?