Get last element in Bash array
<p>Say I have an array:</p>

<pre><code>arr=(a b c d e f)
</code></pre>

<p>If I want to get the last element of the array, I normally have to get the total number of elements, substract one and use that number to call as an index:</p>

<pre><code>$ echo ${#arr[@]}
6
$ echo ${arr[${#arr[@]}-1]}
f
</code></pre>

<p>However, <a href="https://stackoverflow.com/questions/36933682/increment-variable-in-a-string-in-shell-script/36933953#comment61474656_36933953">I see</a> that recently (Bash 4.2 - 4.3) you can use negative indexes:</p>

<pre><code>$ echo ${arr[-1]}
f
$ echo ${arr[-2]}
e
</code></pre>

<p>So I am wondering: when was this introduced? Is it also usable by other shells like ksh, zsh...?</p>

<p>My research shows:</p>

<p><a href="http://bug-bash.gnu.narkive.com/WtOy6UGI/bash-4-3-rc1-available-for-ftp" rel="noreferrer">Bash-4.3-rc1 available for FTP</a></p>

<blockquote>
  <p>a. Fixed a bug that caused assignment to an unset variable using a
  negative subscript to result in a segmentation fault.</p>
  
  <p>b. Fixed a bug that caused assignment to a string variable using a
  negative subscript to use the incorrect index.</p>
  
  <p>...</p>
  
  <p>x. The shell now allows assigning, referencing, and unsetting elements
  of indexed arrays using negative subscripts (a[-1]=2, echo ${a[-1]})
  which count back from the last element of the array.</p>
</blockquote>

<p>And <a href="http://www.gnu.org/software/bash/manual/bashref.html#Arrays" rel="noreferrer">Bash manual 4.3, on Arrays</a></p>

<blockquote>
  <p>Referencing an array variable without a subscript is equivalent to
  referencing with a subscript of 0. If the subscript used to reference
  an element of an indexed array evaluates to a number less than zero,
  it is interpreted as relative to one greater than the maximum index of
  the array, so negative indices count back from the end of the array,
  and an <strong>index of -1 refers to the last element</strong>.</p>
</blockquote>

<p>But I wonder if this was already in Bash 4.2, since the first resource mentions a bug that was fixed.</p>