0

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?

Michel
  • 769
  • 4
  • 19
Aankhen
  • 2,198
  • 11
  • 19
  • 1
    It looks like `ash` is applying `:` to a single string formed from the positional arguments, rather than the "array" of arguments. Not sure if that's a bug or expected (but undocumented) behavior. In `dash` it's just a "bad substitution" error. – chepner Mar 26 '19 at 15:30
  • Interesting. Thank you for the context. – Aankhen Mar 26 '19 at 15:46

1 Answers1

3

${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
chepner
  • 497,756
  • 71
  • 530
  • 681