简体   繁体   中英

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:

allparameters() { echo "$@"; }

Which gives me:

$ allparameters yyyyy abffcd efgh
yyyyy abffcd efgh

I want to skip yyyyy , so I tried ${@: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. What is the equivalent?

${name:offset} is a bash ism, but you can use the POSIX shift command for what you want.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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