In array operator in bash

前端 未结 9 1962
无人及你
无人及你 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

    if you just want to check whether an element is in array, another approach

    case "${array[@]/one/}" in 
     "${array[@]}" ) echo "not in there";;
     *) echo "found ";;
    esac
    

提交回复
热议问题