猛砸,参数列表段
问题描述:
如果您有蟒蛇的列表,你想从2到n的元素可以做一些漂亮的像
If you have a list in python, and you want the elements from 2 to n can do something nice like
list[2:]
我想在Bash中使用的argv类似的东西。我想通过所有从$ 2元argc那样的命令。我目前有
I'd like to something similar with argv in Bash. I want to pass all the elements from $2 to argc to a command. I currently have
command $2 $3 $4 $5 $6 $7 $8 $9
但小于优雅。会是正确的方法是什么?
but this is less than elegant. Would would be the "proper" way?
答
您可以做的切片,以及 $ @
得到所有的参数在bash。
you can do "slicing" as well, $@
gets all the arguments in bash.
echo "${@:2}"
第二次获取论据起
gets 2nd argument onwards
例如
$ cat shell.sh
#!/bin/bash
echo "${@:2}"
$ ./shell.sh 1 2 3 4
2 3 4