Reputation: 17
I'm trying to print the line for each directory, if the directory/file does not exist i need to display "missing".
file="file.txt"
if [[ -d "$/folders/folder1" && -d "$/folders/folder1" ...]]; then
if [ -e "$file" ]; then
#the files that exist and contain the file, call the function
for i in folder{1..11}; do
echo $i function
done
else
#for the directories that don't exist
echo "no directory exists"
fi
else
#for the directories that don't exist
echo "no directory exists"
Upvotes: 0
Views: 715
Reputation: 7499
Regarding your requirements from the comments, you can do this:
#!/usr/bin/env bash
do_stuff() {
local file=$1
local score max junk
IFS=$'/ \t' read -r score max junk < <(tail -n 1 "$file")
echo "$score / $max"
}
file="feedback.txt"
for dir in folders/folder{1..11}; do
if ! [[ -f "$dir/$file" ]]; then
echo "${dir##*/}: missing"
continue
fi
#OK - do stuff here
do_stuff "$dir/$file"
done
Upvotes: 2