, , (a) Bash , () . , , .
:
#!/bin/bash
declare -A array_test()
array_test=(["text1"]="" ["text2"]="" ["text3"]="" ["text4"]="" ["text5"]="")
text_to_search="text4"
if
[[ ${array_test[$text_to_search]+found} ]]
then
echo "Found!"
fi
, , ( , , ).
- . , , , Bash , , . , , .
, , , :
for key in "${!array[@]}"
do
do_something_with_the key
done
, , , . :
declare -A array_test=()
while IFS= read -r key
do
array_test[$key]=
done < <(command_with_output)
, , () , unset. , :
declare -A array_test=()
array_test[existing_key]=
echo ${array_test[existing_key]+found}
echo ${array_test[missing_key]+found}
"${var+value}" , , , value, . set -u, .