在bash中获取位置参数 [英] getting positional arguments in bash
本文介绍了在bash中获取位置参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为foo的bash脚本,带有可变数量的参数,第一个是必需的参数,即:
I have a bash script called foo with variable number of arguments, with the first one being a required one, i.e.:
foo a1 b2 b3 b4 ...
我知道在bash中$ 1会给我参数a1,但是有没有办法得到其余所有参数呢?$ @或$ *似乎让我理解了包括a1在内的所有参数.
I understand that in bash $1 will get me argument a1, but is there a way to get all the rest of the arguments? $@ or $* seem to get me all the arguments including a1.
推荐答案
切片 $ @
数组.
echo "${@:2}"
这篇关于在bash中获取位置参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文