Need Help with Bash - comparing directory contents with list of files

Hey guys,

need help with a script I'm trying to write.

Basically I need to compare the contents of a folder called "profiles"
with a list of files called "template".

when the file matches the contents of the folder it needs to set a variable called "checked" to "1"

Cookies to anyone who can help :slight_smile:

thanks in advance

#!/bin/bash
ls -ltr folder1 > list-of-files-1.txt
ls -ltr folder2 > list-of-files-2.txt
i=1
while read line; do
  if [ "cat list-of-files-1.txt | head -$i | tail -1" = "$line" ]; then
    put-1-wherever-you-want
    i=$i+1
  fi
done < list-of-files-2.txt

Explanation: You should do 2 lists of files. After that, you have to compare those lists by line. If both lists have the same element in the same position, you can put a number 1 wherever you want.

That is Useless Use of Cat. You can simply code:

checked=1
while read file
do
        [[ ! -f profiles/$file ]] && checked=0; [[ "$checked" -eq 0 ]] && break;
done < template

Note: Replace highlighted with absolute path of dir: profiles

Wow, I didn't knew that. Thanks!

anyway i could work in something to echo an error if the check fails?