Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14672

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

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Ilkka Virta <itvirta@iki.fi>
Newsgroups gnu.bash.bug
Subject Re: comment on RFE: 'shift'' [N] ARRAYNAME
Date Thu, 27 Sep 2018 18:47:33 +0300
Lines 37
Approved bug-bash@gnu.org
Message-ID <mailman.1403.1538063267.1284.bug-bash@gnu.org> (permalink)
References <5BAAD017.4010806@tlinx.org> <20180927123551.j5attjixprhoxavx@eeg.ccf.org>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace usenet.stanford.edu 1538063268 8212 208.118.235.17 (27 Sep 2018 15:47:48 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.9.1
In-Reply-To <20180927123551.j5attjixprhoxavx@eeg.ccf.org>
Content-Language en-US
X-SASI-RCODE 200
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; h=subject:to:references:from:message-id:date:mime-version:in-reply-to:content-type:content-transfer-encoding; s=smtp; bh=hZCpodnWR4yDV6Ea99o8l+lYQ6EMscxat4UxA9SjmI4=; b=Z5gaX7x/hb8+P+ve6zuMpjOV7CcrLN88iZNJPKoeWlLBxH2YtvUVm+FtgNszX9n0TJFnGN2n0MBdFnuDsDgk5c3Nzx/MLteqqbBmq3KqW/OOrp8ojjO6Gr4b+gFXMrG/NeZ9HX28J4rR1JbcP8lMr9TOqudrJwDwHZZhxedGws8HMaLTi9mbJxe15gEsj+bHglhKvbFUL+fxQy2CQwFU8ynfEHTYdosracN2Bb2I7jqGFuDB46EVBe2KrMt9H9RD0VaY6XSXSPq/Ft5NsRlICdF4fgn2K3Wy8h0J1+yf0r2R6SefBsOLriwEtCvzUEEe4km+jfxYTg581MIrfbhVHw==
X-detected-operating-system by eggs.gnu.org: FreeBSD 8.x
X-Received-From 157.24.2.104
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:14672

Show key headers only | View raw


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";
      _arr_=("${_arr_[@]:${2-1}}");
  }
  somearray=(a b c d)
  ashift somearray 2


-- 
Ilkka Virta / itvirta@iki.fi

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: comment on RFE: 'shift'' [N] ARRAYNAME Ilkka Virta <itvirta@iki.fi> - 2018-09-27 18:47 +0300

csiph-web