处理所有的参数,除了第一个 [英] Process all arguments except the first one

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

问题描述

我有一个简单的脚本,第一个参数是保留的文件名,和所有其他可选参数应该传递给脚本的其他部分。

I have a simple script where the first argument is reserved for the filename, and all other optional arguments should be passed to other parts of the script.

使用谷歌,我发现这个wiki ,但它提供了一个文字的例子:

Using Google I found this wiki, but it provided a literal example:

echo "${@: -1}"

我不能让别的工作,如:

I can't get anything else to work, like:

echo "${@:2}"

echo "${@:2,1}"

我收到坏替代从终端。

I get "Bad substitution" from the terminal.

这是什么问题,我怎么可以处理所有,但传递给bash脚本的第一个参数?

What is the problem, and how can I process all but the first argument passed to a bash script?

推荐答案

使用这样的:

echo "${@:2}"


的语法如下:


The following syntax:

echo "${*:2}"

也行,但不建议,因为作为<一个href=\"http://stackoverflow.com/questions/9057387/process-all-arguments-except-the-first-one#comment11369452_9057392\">@Gordon已经说明,在使用 * ,它运行的所有参数看作带有空格的一个参数,而 @ preserves它们之间的休息时间(即使某些参数本身包含空格)。它不会使回声与的区别,但它的问题很多其他的命令。

would work as well, but is not recommended, because as @Gordon already explained, that using *, it runs all of the arguments together as a single argument with spaces, while @ preserves the breaks between them (even if some of the arguments themselves contain spaces). It doesn't make the difference with echo, but it matters for many other commands.

这篇关于处理所有的参数,除了第一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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