0

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

2
  • 1
    The list = ['pic1','pic2','pic3']; notation is not an assignment in bash; it is an invocation of the command list with two arguments, one of which is an equals sign and the other of which is "[pic1,pic2,pic3]" when the command sees it. Commented May 3, 2011 at 14:45
  • I agree with Jonathan. Please either fix this question or delete it. Commented May 3, 2011 at 21:55

1 Answer 1

0
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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.