I am writing a bash script that will
- Downlaod a website's html code into a file "index.html"
- Ask user for file type and search "index.html" for number of matched file types
This is the function that will complete step 2:
1. function findFiles() {
2. echo "Enter file type to search for (include '.') || Type EXIT to terminate program "
3. read fileType
4.
5. while [[ "$fileType" != "EXIT" ]];
6. do
7. if [[ $(grep -q $fileType index.html) = 1 ]]; then
8. grep -F "$fileType" index.html >> foundFiles.txt
9. fi
10. done
11.
12. rm index.html
13. };
When executed, line 3 prompts for user input but does not respond when I hit enter, example follows:
2021-09-26 12:41:06 (2.66 MB/s) - ‘index.html’ saved [94126]
Enter file type to search for (include '.') || Type EXIT to terminate program
.pdf
.txt
foo
AAAA
I have tried declaring a local variable $fileType
first, using read -p
and putting a semicolon at the end of line 3. The result is always the same and I have not been able to find a solution. I'm aware that what follows line 3 is flawed, but I just would only like help with line 3 as the following lines are something I would like to work on myself to learn more about bash scripting.
Any ideas are appreciated.