Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14672 > unrolled thread
| Started by | Ilkka Virta <itvirta@iki.fi> |
|---|---|
| First post | 2018-09-27 18:47 +0300 |
| Last post | 2018-09-27 18:47 +0300 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: comment on RFE: 'shift'' [N] ARRAYNAME Ilkka Virta <itvirta@iki.fi> - 2018-09-27 18:47 +0300
| From | Ilkka Virta <itvirta@iki.fi> |
|---|---|
| Date | 2018-09-27 18:47 +0300 |
| Subject | Re: comment on RFE: 'shift'' [N] ARRAYNAME |
| Message-ID | <mailman.1403.1538063267.1284.bug-bash@gnu.org> |
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 top | Article view | gnu.bash.bug
csiph-web