arr1包含元素“ a”,“ b”,“ c”
arr2包含元素“ b”
如果arr1中存在arr2的元素,则执行...。
我该怎么写?
类似
for x in arr1
do
if [ ${arr1[x]} == ${arr2[*]} ]
then ...
fi
done
?
答案 0 :(得分:0)
检查arr1中存在的arr2中的值:
arr1=("a" "b" "c")
arr2=("c" "d" "e")
for i in "${arr2[@]}"
do
for j in "${arr1[@]}"
do
[[ "$i" == "$j" ]] && echo "$i"
done
done
->打印:c