我想知道如何获取传递给 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/