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

Community
  • 1
  • 1
Mahakaal
  • 1,835
  • 9
  • 26
  • 35
  • 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. – Jonathan Leffler May 03 '11 at 14:45
  • I agree with Jonathan. Please either fix this question or delete it. – shellter May 03 '11 at 21:55

1 Answers1

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.

l0b0
  • 48,420
  • 21
  • 118
  • 185