In array operator in bash

前端 未结 9 1749
无人及你
无人及你 2021-02-19 22:20

Is there a way to test whether an array contains a specified element?

e.g., something like:

array=(one two three)

if [ \"one\" in ${array} ]; then
...
f         


        
9条回答
  •  清歌不尽
    2021-02-19 22:27

    Try this:

    array=(one two three)
    if [[ "${array[*]}" =~ "one" ]]; then
      echo "'one' is found"
    fi
    

提交回复
热议问题