8.6 What arrays contain

Function: mbfl_array_contains ARRY_VAR KEY

Return successfully if KEY is set in the array referenced by ARRAY_VAR.

declare -a ARRY=([0]=a [1]=b [2]=c)

mbfl_array_contains    ARRY 0 &&
   mbfl_array_contains ARRY 1 &&
   mbfl_array_contains ARRY 2 &&
   ! mbfl_array_contains ARRY 3
Function: mbfl_array_contains_value_var RV ARRY_VAR VALUE

Return successfully if VALUE is a value in the array; store the associated key in the result variable RV.

mbfl_declare_index_array_varref(ARRY, ([0]=a [1]=b [2]=c))
mbfl_declare_varref(KEY)

mbfl_array_contains_value_var mbfl_datavar(KEY) mbfl_datavar(ARRY) a
⇒ 0
"$KEY"  ⇒ 0
Function: mbfl_array_contains_all_keys ARRY_VARNAME KEYS_VARNAME

Return true if the array ARRY_VARNAME contains, as keys, all the values in the index array KEYS_VARNAME; otherwise return false.

mbfl_declare_assoc_array_varref(ARRY, ([alpha]=1 [beta]=2 [gamma]=3))
mbfl_declare_index_array_varref(KEYS, (alpha gamma))

mbfl_array_contains_all_keys mbfl_datavar(ARRY) mbfl_datavar(KEYS)
⇒ 1

mbfl_declare_index_array_varref(KEYS, (alpha gamma delta))

mbfl_array_contains_all_keys mbfl_datavar(ARRY) mbfl_datavar(KEYS)
⇒ 0
Function: mbfl_array_contains_all_keys_and_only ARRY_VARNAME KEYS_VARNAME

Return true if the array ARRY_VARNAME contains, as keys, all the values in the index array KEYS_VARNAME and only those; otherwise return false.

mbfl_declare_assoc_array_varref(ARRY, ([alpha]=1 [beta]=2 [gamma]=3))

mbfl_declare_index_array_varref(KEYS, (alpha beta gamma))
mbfl_array_contains_all_keys_and_only mbfl_datavar(ARRY) mbfl_datavar(KEYS)
⇒ 0

mbfl_declare_index_array_varref(KEYS, (alpha gamma))
mbfl_array_contains_all_keys_and_only mbfl_datavar(ARRY) mbfl_datavar(KEYS)
⇒ 1

mbfl_declare_index_array_varref(KEYS, (alpha beta gamma delta))
mbfl_array_contains_all_keys_and_only mbfl_datavar(ARRY) mbfl_datavar(KEYS)
⇒ 1

This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.