-1

Suppose such a minimal task to select elements in B but not in A

file_list1=(a.sh b.sh c.sh)
file_list2=(b.sh c.sh d.sh)

for i in files_list1; do
    for k in files_list2; do
        if [[ $k in $(echo $i) ]]; then
        echo 
        else
        echo $k
        fi
    done
done

it report errors:

$ bash compare.sh 
compare.sh: line 5: conditional binary operator expected
compare.sh: line 5: syntax error near `in'
compare.sh: line 5: `        if [[ $k in $(echo $i) ]]; then'

if not apply in, how could get the code working?

Wizard
  • 2,503

1 Answers1

2

Beside the logic, you have this syntax errors:

  • It is file_list, not files_list.
  • To expand to array elements you need to use "${file_list[@]}".

Try Shellcheck before posting.

If you must do it in the shell, then try:

file_list1=(a.sh b.sh c.sh)
file_list2=(b.sh c.sh d.sh)

for i in "${file_list1[@]}"; do
    repeated_in_A=0
    for k in "${file_list2[@]}"; do
        if [[ $k == $i ]]; then
            repeated_in_A=1
        break 
        fi
    done
    ((repeated_in_A)) || echo "$k"
done