且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查一个字符串是否在数组中没有遍历元素呢?

更新时间:2023-11-28 22:37:46

在bash 4,你能做的最接近的事是使用关联数组。

With bash 4, the closest thing you can do is use associative arrays.

declare -A map
for name in hello world my name is perseus; do
  map["$name"]=1
done

tgt=henry
if [[ ${map["$tgt"]} ]] ; then
  : found
fi