如何获得在bash的第n个位置参数? [英] How to get the nth positional argument in bash?
本文介绍了如何获得在bash的第n个位置参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让 N
日在bash位置参数?
How to get the n
th positional argument in bash?
感谢。
编辑:我忘了说了,但我的意思是 N
是一个变量
I forgot to say but I meant that n
is a variable.
推荐答案
使用bash的间接功能:
Use Bash's indirection feature:
#!/bin/bash
n=3
echo ${!n}
运行该文件:
$ ./ind apple banana cantaloupe dates
产地:
cantaloupe
编辑:
您也可以做数组切片:
echo ${@:$n:1}
而不是数组下标:
but not array subscripts:
echo ${@[n]} # WON'T WORK
这篇关于如何获得在bash的第n个位置参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文