Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14670 > unrolled thread
| Started by | Dennis Williamson <dennistwilliamson@gmail.com> |
|---|---|
| First post | 2018-09-27 07:42 -0500 |
| Last post | 2018-09-27 07:42 -0500 |
| 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 Dennis Williamson <dennistwilliamson@gmail.com> - 2018-09-27 07:42 -0500
| From | Dennis Williamson <dennistwilliamson@gmail.com> |
|---|---|
| Date | 2018-09-27 07:42 -0500 |
| Subject | Re: comment on RFE: 'shift'' [N] ARRAYNAME |
| Message-ID | <mailman.1387.1538052159.1284.bug-bash@gnu.org> |
On Tue, Sep 25, 2018, 7:17 PM L A Walsh <bash@tlinx.org> wrote:
> 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
>
>
>
> "my" - What is this, Perl?
array_shift=2
arr=("${arr[@]:$array_shift}")
Done.
>
Back to top | Article view | gnu.bash.bug
csiph-web