shellashdash-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:

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?


Solution

  • ${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