Bash arrays and negative subscripts, yes or no?

后端 未结 5 1971
感动是毒
感动是毒 2021-02-08 00:32

The GNU bash manual tells me

An indexed array is created automatically if any variable is assigned to using the syntax

name[subscript]=v         


        
5条回答
  •  情书的邮戳
    2021-02-08 00:51

    If you just want the last element

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

    If you want next to last element

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

提交回复
热议问题