[Top][All Lists]

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

Re: comment on RFE: 'shift'' [N] ARRAYNAME

From: Ilkka Virta
Subject: Re: comment on RFE: 'shift'' [N] ARRAYNAME
Date: Thu, 27 Sep 2018 18:47:33 +0300
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

On 27.9. 15:35, Greg Wooledge wrote:
Shift already takes one optional argument: the number of items to shift
from the argv list.  Adding a second optional argument leads to a quagmire.
Do you put the optional list name first, or do you put the optional number
first?  If only one argument is given, is it a list name, or is it a number?

(OK, granted, in bash it is not permitted to create an array whose name
is strictly digits, but still.)

Can you make an array whose name even starts with a digit?

With no overlap between array names and valid numbers,
shift [arrayname] [n]   would be unambiguous, as you said.

Though shift [n [arrayname]] would be even more backward-compatible since the new behaviour would always require two arguments, which is now an error.

Even so, deciding how to handle sparse arrays might an interesting issue, too.

If one wants a command that looks like the current shift, Dennis's obvious slice-assignment could be wrapped in a function. Doing it this way of course collapses the indices to consecutive numbers starting at zero.

 ashift() {
     typeset -n _arr_="$1";
 somearray=(a b c d)
 ashift somearray 2

Ilkka Virta / address@hidden

reply via email to

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