[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: last element of an array
From: |
Chet Ramey |
Subject: |
Re: last element of an array |
Date: |
Thu, 24 May 2007 10:47:14 -0400 |
User-agent: |
Thunderbird 2.0.0.0 (Macintosh/20070326) |
Poor Yorick wrote:
> The syntax I'm currently using to access the last element of an array looks a
> little evil:
>
>> arr=( one two three )
>> echo ${arr[$((${#arr[@]}-1))]}
> three
>
> If there is not currently a friendlier syntax for this, might I suggest:
>
> ${arr[-1]}
What's wrong with echo ${arr[@]: -1} ?
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
Live Strong. No day but today.
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/