Bash arrays and negative subscripts, yes or no? Bash arrays and negative subscripts, yes or no? bash bash

Bash arrays and negative subscripts, yes or no?


If you just want the last element

$ echo ${muh[*]: -1}2

If you want next to last element

$ echo ${muh[*]: -2:1}bleh


According to Greg Wooledge's wiki, (which links to the bash changelog) the negative index syntax was added to bash in version 4.2 alpha.


If you do man bash the section on arrays does not list this behavior. It might be something new (gnu?) in bash.

Fails for me in CentOS 6.3 (bash 4.1.2)