Я создал тестовые каталоги и файлы, чтобы показать, как это можно сделать.
Создать каталоги dir1 and
dir2`
mkdir -p dir{1..2}
Проверить каталоги.
ls
dir1 dir2
Создание файлов.
touch dir{1..2}/{1..10}.txt
Проверка файлов.
ls dir{1..2}/
dir1/:
10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
dir2/:
10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
Создание содержимого файла.
printf '%s\n' {1..10}.txt > list_of_files.txt
printf '%s\n' {a..c} >> list_of_files.txt
Проверка содержимого файла.
cat list_of_files.txt
Выходные данные
1.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt
10.txt
a
b
c
Переменная foo
равна dir1
, а переменная bar
равна dir2
в сценарии.
#!/bin/sh
foo=dir1
bar=dir2
while read -r files_in_text; do
if [ ! -e "$foo"/"$files_in_text" ] && [ ! -e "$bar"/"$files_in_text" ]; then
printf 'files %s and %s does not exists!\n' "$foo"/"$files_in_text" "$bar"/"$files_in_text"
else
printf 'files %s and %s does exists.\n' "$foo"/"$files_in_text" "$bar"/"$files_in_text"
fi
done < list_of_files.txt
Вывод должен быть
files dir1/1.txt and dir2/1.txt does exists.
files dir1/2.txt and dir2/2.txt does exists.
files dir1/3.txt and dir2/3.txt does exists.
files dir1/4.txt and dir2/4.txt does exists.
files dir1/5.txt and dir2/5.txt does exists.
files dir1/6.txt and dir2/6.txt does exists.
files dir1/7.txt and dir2/7.txt does exists.
files dir1/8.txt and dir2/8.txt does exists.
files dir1/9.txt and dir2/9.txt does exists.
files dir1/10.txt and dir2/10.txt does exists.
files dir1/a and dir2/a does not exists!
files dir1/b and dir2/b does not exists!
files dir1/c and dir2/c does not exists!