[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] opposite of 'shift'
From: |
Peng Yu |
Subject: |
Re: [Help-bash] opposite of 'shift' |
Date: |
Thu, 16 Feb 2012 07:44:47 -0600 |
On Thu, Feb 16, 2012 at 12:52 AM, Pierre Gaston <address@hidden> wrote:
>
>
> On Thu, Feb 16, 2012 at 8:47 AM, Peng Yu <address@hidden> wrote:
>>
>> Hi,
>>
>> I'm wondering what is the opposite of 'shift'. I'm trying to look for
>> something like 'push', 'push_front', etc. But I don't find it. Is
>> there something in bash that do push to the front of an array (and to
>> "$@" by default)?
>>
>
> There's no opposite only:
> set -- blah "$@"
I recall now that I have seen this before. I think that it is probably
better to have some function like 'unshift' to make operation
symmetric. Many other languages have symmetric functions. Bash
probably should be improved in these aspects. For example, in perl, it
has the following (see
http://www.cs.cmu.edu/afs/cs/usr/rgs/mosaic/pl-exp-arr.html)
shift
Shifts the first value of the array off and returns it, shortening
the array by 1 and moving everything down. If there are no elements in
the array, returns the undefined value. If ARRAY is omitted, shifts
the @ARGV array in the main program, and the @_ array in subroutines.
(This is determined lexically.) See also unshift(), push() and pop().
Shift() and unshift() do the same thing to the left end of an array
that push() and pop() do to the right end.
> It's probably a better idea to implement whatever structure you want with an
> array
--
Regards,
Peng
- [Help-bash] opposite of 'shift', Peng Yu, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Pierre Gaston, 2012/02/16
- Re: [Help-bash] opposite of 'shift',
Peng Yu <=
- Re: [Help-bash] opposite of 'shift', Greg Wooledge, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Peng Yu, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Greg Wooledge, 2012/02/16
- Re: [Help-bash] opposite of 'shift', lxnf98mm, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Pierre Gaston, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Chet Ramey, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Chet Ramey, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Eric Blake, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Peng Yu, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Greg Wooledge, 2012/02/17