开发者

How to find the presence of element in bash array [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Bash: check if an array contains a value

i have list like

list = ['pic1','pic2','pic3'];

i am in array like

for a in /dir/star
if(a is in list then skip the 开发者_开发问答loop)
do
echo "hello";
done

I want to skip the loop if element is in list


for path in /dir/*
do
    for val in pic1 pic2 pic3
    do
        if [ "$(basename -- "$path")x" = "${val}x" ]
        then
            continue 2 # Next path
        fi
    done
    # No match, do whatever you want
done

If you want to end processing completely after finding the first match, just replace continue with break.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜