检查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
慕侠2389804
千万里不及你
陪伴而非守候
小怪兽爱吃肉
随时随地看视频慕课网APP
相关分类