1. echo "${array[@]}" | grep -wq "$var" &&echo "Yes" || echo "No"
2. for i in ${array[@]}
do
[ "$i" == "$var" ] && echo "yes"
done
3.
- test_array ()
- {
- y_n=$1
-
- arr=$2
-
- echo $(eval echo \${$arr[@]}) |\
- sed 's/ /\n/g' |\
- while read line
- do
- if [ "$y_n" == "$line" ]
- then
- return 1
- break
- else
- continue
- fi
- ((i++))
- done
- }
-
- test_array $var array