I understand how to iterate through lines in a local file. But how about a remote file?
while read NAME
do
    echo "$NAME"
done < curl -sL 'http://mylistofnames.com/list.html
If this were local, I would replace the last line with done < names.txt. I'm stuck on remote.
Put the curl command in a bash process substitution:
while read NAME
do
    echo "$NAME"
done < <(curl -sL 'http://mylistofnames.com/list.html')
Piping works as well, but if variables are set in the while loop and they are needed outside the scope of the while loop then this solution becomes necessary.
Pipe the output:
curl -sL 'http://mylistofnames.com/list.html' | while read NAME
    do echo "$NAME"
done
With process substitution:
while read NAME
    do echo "$NAME"
done < <(curl -sL 'http://mylistofnames.com/list.html')
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With