Get the index of a value in a Bash array

后端 未结 15 513
说谎
说谎 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:28

    In zsh you can do

    xs=( foo bar qux )
    echo ${xs[(ie)bar]}
    

    see zshparam(1) subsection Subscript Flags

提交回复
热议问题