-
-
Save likohank/5dec12b808d6b3577dd9d8b3bb6a22b5 to your computer and use it in GitHub Desktop.
Revisions
-
likohank created this gist
Aug 28, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ if [[ " ${array[@]} " =~ " ${value} " ]]; then # whatever you want to do when arr contains value fi ------------------------------------------------------ if [[ ! " ${array[@]} " =~ " ${value} " ]]; then # whatever you want to do when arr doesn't contain value fi ------------------------------------------------------ if [[ " ${!array[@]} " =~ " ${value} " ]]; then # whatever you want to do when arr contains value fi ------------------------------------------------------ ${!array[@]} 获取所有的key ${array[@]} 获取所有的value ------------------------------------------------------ Indexed arrays use positive integer numbers as keys. Shell 的 Array 数组 使用正整数作为key -------------------- http://wiki.bash-hackers.org/syntax/arrays array=() declare -a ARRAY 直接声明的数组不支持 字符串做为索引,只支持正整数作为key。 如要要声明 关系型数组,需要使用 declare -A ARRAY declare -A ARRAY Declares an associative array ARRAY. This is the one and only way to create associative arrays. ------------------------------------------------------