In array operator in bash

前端 未结 9 1888
无人及你
无人及你 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条回答
  •  梦毁少年i
    2021-02-19 22:33

    OPTIONS=('-q','-Q','-s','-S')
    
    find="$(grep "\-q" <<< "${OPTIONS[@]}")"
    if [ "$find" = "${OPTIONS[@]}" ];
    then
        echo "arr contains -q"
    fi
    

提交回复
热议问题