function in_list {
SEARCH="$1"; shift
LIST=( "$@" )
if [ -z "${LIST}" ] || [ -z "${SEARCH}" ]; then
return 1
fi
for ITEM in ${LIST[@]}; do
if [[ "${ITEM}" == "${SEARCH}" ]]; then
return 0
fi
done
return 1
}
LIST=( "foo" "bar" "with space" "fiz" "buz" )
if (in_list "bar" "${LIST[@]}"); then
echo "bar is in MY_LIST"
fi
Sortie :
bar is in MY_LIST