help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Taking a slice of an array


From: Bill Gradwohl
Subject: Re: [Help-bash] Taking a slice of an array
Date: Mon, 9 Apr 2012 08:48:00 -0600

On Mon, Apr 9, 2012 at 7:22 AM, Greg Wooledge <address@hidden> wrote:
At this point, you're doing something odd.  You're using "$@" syntax
(which results in multiple words), but you're doing it on the right-hand
side of an assignment, which means you're forcing there to be just one
word.  The two are fundamentally incompatible, and in this case, the
assignment (forcing one word) wins.

Thank You Greg.

I suggest then that this is a weak spot in the docs.
 Parameter Expansion
       ${parameter:offset}
       ${parameter:offset:length}
If parameter is an indexed array name subscripted by @ or *, the result is the length members of the array beginning with ${parameter[offset]}.

This makes no distinction between @ and *, and never mentions IFS. It never occurred to me to try * due to the docs.

Reading this section also made me think it was talking about each array element converted to a character string and then the strings concatenated, when now I realize that the output is perfectly suitable to put inside ( ) to actually assign the sliced elements to another array. In that context the spaces make perfect sense.

A few examples sprinkled in man bash would go a long way towards clarifying things.

 
IFS is only used by the "$*" notation, not by the "$@" notation.

I never realized that IFS was * only. Thanks for that nugget.

--
Bill Gradwohl


reply via email to

[Prev in Thread] Current Thread [Next in Thread]