Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 9
    +1 for learning about an array needing to be at the end and that only one should be sent Commented Sep 21, 2018 at 11:03
  • 9
    It's also useful to use shift's argument sometimes, so if you had 6 arguments before the array, you can use shift 6. Commented Jul 4, 2019 at 17:49
  • You convert "the rest of arguments" into arr. Is it possible to have an array parameter in the middle? Or even several arrays parameters? function copyAndMove() { msg1=$1 ; arr1=...?... ; msg2=? ; arr2=...?... ; msg3=? ; ... }. Like I would define it in python: def copyAndMove(msg1="foo", cpFiles=[], msg2="bar", mvFiles=[], msg3="baz"): .... Never mind, I found stackoverflow.com/a/4017175/472245
    – towi
    Commented Oct 25, 2019 at 7:07
  • Explained really well. and didn't know about shift. Thanks.
    – Sannu
    Commented May 8, 2020 at 22:59
  • 5
    You can also achieve same behavior without using shift by doing this: local msg="$1"; local -a arr=( "${@:2}" ) Commented May 28, 2020 at 1:32