如何获取shell中的最后一个参数
How to get the last parameter in shell
我想知道如何获取传递给 bash 函数的最后一个参数,如下所示:
#!/bin/bash
function hello() {
all=$@ # all arguments
n=$# # number of arguments
first_arg= # argument one
last_arg= ??? # How to get the last argument?
}
如何将 $last_arg
设置为传递给函数的最后一个参数的值?
如果all
持有$@
,那么最后一个参数是${all[*]: -1}
我想知道如何获取传递给 bash 函数的最后一个参数,如下所示:
#!/bin/bash
function hello() {
all=$@ # all arguments
n=$# # number of arguments
first_arg= # argument one
last_arg= ??? # How to get the last argument?
}
如何将 $last_arg
设置为传递给函数的最后一个参数的值?
如果all
持有$@
,那么最后一个参数是${all[*]: -1}