猛砸,参数列表段 [英] Bash, argument list segment

查看:167
本文介绍了猛砸,参数列表段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有蟒蛇的列表,你想从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

这篇关于猛砸,参数列表段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆