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


Groups > gnu.bash.bug > #14664

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

Path csiph.com!goblin3!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From L A Walsh <bash@tlinx.org>
Newsgroups gnu.bash.bug
Subject comment on RFE: 'shift'' [N] ARRAYNAME
Date Tue, 25 Sep 2018 17:17:27 -0700
Lines 34
Approved bug-bash@gnu.org
Message-ID <mailman.1328.1537921058.1284.bug-bash@gnu.org> (permalink)
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 1537921059 26698 208.118.235.17 (26 Sep 2018 00:17:39 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash <bug-bash@gnu.org>
Envelope-to bug-bash@gnu.org
User-Agent Thunderbird
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy]
X-Received-From 173.164.175.65
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:14664

Show key headers only | View raw


It struck me as it might be convenient if 'shift' could take an optional
arrayname as an argument.  Would that be possible or would it cause some
incompatibility?

i.e.

>  set one two three four five
>  dcl -a ARGV=("$@")
>  shift ARGV
>  echo "${ARGV[@]}"
two three four five
>  shift 2 ARGV
four five

I know it can be done with a function, but with more mess.
I used (maybe there's a better way, but...):

(in my lib file ArFuncs.shh, that I can include)

[include stdalias]
#[include Types] #if type-checking include Types+line below
lshift () {
  (($#)) || return 1
  int nshift=1
  if [[ $1 =~ ^[0-9]+$ ]]; then nshift=$1; shift;fi
  #if ! isArr $1; then echo >&2 "Need arrayname"; return 1; fi
  my ar=$1; shift
  my h="$ar[@]"
  set "${!h}"
  shift $nshift
  eval "${ar}=("$@")"
}; export -f lshift

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


Thread

comment on RFE: 'shift'' [N] ARRAYNAME L A Walsh <bash@tlinx.org> - 2018-09-25 17:17 -0700

csiph-web