检查Bash数组是否包含值
编辑
function contains() { local n=$# local value=${!n} for ((i=1;i < $#;i++)) { if [ "${!i}" == "${value}" ]; then echo "y" return 0 fi } echo "n" return 1}A=("one" "two" "three four")if [ $(contains "${A[@]}" "one") == "y" ]; then echo "contains one"fiif [ $(contains "${A[@]}" "three") == "y" ]; then echo "contains three"fi
守着星空守着你
汪汪一只猫
沧海一幻觉