简体   繁体   English

如何跳过 ash/dash shell 函数中的第一个参数?

[英]How can I skip the first argument in an ash/dash shell function?

In an ash/dash function, I can refer to the full parameter list like this:在 ash/dash 函数中,我可以像这样引用完整的参数列表:

allparameters() { echo "$@"; }

Which gives me:这给了我:

$ allparameters yyyyy abffcd efgh
yyyyy abffcd efgh

I want to skip yyyyy , so I tried ${@:2} :我想跳过yyyyy ,所以我尝试了${@:2}

butlast() { echo "${@:2}"; }

However, this skips the first two characters:但是,这会跳过前两个字符:

$ butlast yyyyy abffcd efgh
yyy abffcd efgh
$ butlast abffcd efgh
ffcd efgh

I wasn't able to find the colon syntax in the man page for ash, so that may be a bash-ism.我无法在 ash的手册页中找到冒号语法,所以这可能是一种 bash 主义。 What is the equivalent?什么是等价物?

${name:offset} is a bash ism, but you can use the POSIX shift command for what you want. ${name:offset}是一个bash主义,但您可以根据需要使用 POSIX shift命令。

$ butlast() { shift; echo "$@"; }
$ butlast foo bar baz
bar baz

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM