1、定义一个字典变量

declare -A dict
[hduser@yjt hive]$ dict['a']=1
[hduser@yjt hive]$ dict['b']=2
[hduser@yjt hive]$ dict['c']=3

2、判断某个值是否存在于字典的key集合里面
① 使用循环

[hduser@yjt hive]$ for i in ${!dict[*]};do if [ 'a' = $i ];then echo "yes" ;fi;done
yes
[hduser@yjt hive]$ for i in ${!dict[*]};do if [ 'd' = $i ];then echo "yes" ;fi;done
[hduser@yjt hive]$ 

② 使用shell 内置的方式

[hduser@yjt hive]$ if [[ ${!dict[*]/'a'/} != ${arr[*]} ]];then echo 'yes';fi
yes

借鉴:
https://www.cnblogs.com/thatsit/p/bash-shu-zupan-duan-mou-ge-yuan-su-shi-fou-zai-shu.html

相关文章:

  • 2021-11-17
  • 2021-11-07
  • 2022-12-23
  • 2021-11-27
  • 2021-11-07
  • 2021-11-07
  • 2021-11-07
猜你喜欢
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案