Code:
#!/bin/bash
# WEBPAGE LINKS FILE PATH
links_file="website_links.txt"
# (OPTIONAL) KEYWORD TO LOOK FOR
keyword="potato"
if [[ ! -f $links_file ]]; then
printf '« %s »: no such file found.\n' "$links_file" >&2
exit 1
fi
while [[ ! $keyword ]]; then
read -rp 'Enter a keyword to look for: ' keyword
done
while read -r; do
if grep -qi "$keyword" < <(wget -qO- "$REPLY"); then
printf 'Keyword found on: %s\n' "$REPLY"
fi
done < "$links_file"
conoscenza wrote:
In a WHILE loop, what's mean to do: "done < myfile" at the end?
done < myfile is equivalent to
done 0< myfile.
There isn't any connection with the
while loop.
It redirects the file descriptor 0, which is the standard input, to the file
myfile,
so
myfile becomes the standard input instead of your keyboard, then it reads from it.
0 is the standard input by convention. It just is an abstract indicator to work with.
Just remember it as being your keyboard.