Get the index of a value in a Bash array

后端 未结 15 786
说谎
说谎 2021-01-30 03:41

I have something in bash like

myArray=(\'red\' \'orange\' \'green\')

And I would like to do something like

echo ${         


        
15条回答
  •  攒了一身酷
    2021-01-30 04:26

    You must declare your array before use with

    declare -A myArray
    myArray=([red]=1 [orange]=2 [green]=3)
    echo ${myArray['orange']}
    

提交回复
热议问题