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

229 views Asked by At

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?

1

There are 1 answers

0
chepner On BEST ANSWER

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

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