Get the index of a value in a Bash array

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

    There is also one tricky way:

    echo ${myArray[@]/green//} | cut -d/ -f1 | wc -w | tr -d ' '
    

    And you get 2 Here are references

提交回复
热议问题