Loop Script with wget until exit is typed

Morning all,

I am attempting to complete the below script which will do the following (skip the ping part) using Bash.

Prompts the user to type in a URL to download, or to type exit to exit the script.
If a URL is typed, wget to download the webpage and then loop back to prompting for a typed URL or to type exit.
Basically the script continually loops back to prompting for a webpage after the wget is complete of the previous webpage until the user types exit into the prompt

This is what I have now but I'll explain below other things I've tried

I'm not asking for the answer (of course) just a push towards what I should be thinking about. As you can see, I currently have break at line 17 because, of course, without it, it currently will just continue to wget the URL as it gets stuck in an infinite loop. I am sure the solution is simple but I honestly can not wrap my head around how to get it to complete 1 wget and then go back to the url prompt repeatedly until the user types exit.

ECU, WA Australia, CSI6203 Scripting Languages.

1 Like

I am very silly and just thought to use a case statement to achieve what I need to. It is working now.

Please ignore my ramblings :slight_smile:

Have a great day all

Your read statement is out of the loop. So it's stuck infinitely, because $url never changes.

One suggestion:

while : ; do
    read url
    [ "$url" == exit ] && break
    wget ...
done