I am tying to do something quite simple: Run a command for every line in a file.
So far I have this (and have also tried different permutations of this):
URL=$1
COMMENT=${URL##*/}
curl $URL | while read DOMAIN || [[ -n $DOMAIN ]];
do
echo $DOMAIN
echo "pihole -w $DOMAIN --comment $COMMENT -nr"
pihole -w $DOMAIN --comment $COMMENT -nr
done
The echos
are there for debugging. What is happening is the following:
It goes line by line through a file hosted on GitHub and for each of those lines it runs: pihole -w $DOMAIN --comment $COMMENT -nr
- every line is a domain.
However it only runs the full command with the pihole -w $DOMAIN
portion on the last line, the preceding lines only fire with --comment $COMMENT -nr
. As you can see from the output here:
t.ly
--comment url_shorteners.txt -nr
is not a valid argument or domain name!
adf.ly
--comment url_shorteners.txt -nr
is not a valid argument or domain name!
www.adf.ly
--comment url_shorteners.txt -nr
is not a valid argument or domain name!
bit.ly
--comment url_shorteners.txt -nr
is not a valid argument or domain name!
www.bit.ly
--comment url_shorteners.txt -nr
is not a valid argument or domain name!
goo.gl
--comment url_shorteners.txt -nr
is not a valid argument or domain name!
ow.ly
--comment url_shorteners.txt -nr
is not a valid argument or domain name!
www.ow.ly
--comment url_shorteners.txt -nr
is not a valid argument or domain name!
amzn.to
--comment url_shorteners.txt -nr
is not a valid argument or domain name!
amzn.com
pihole -w amzn.com --comment url_shorteners.txt -nr
[i] amzn.com already exists in whitelist, no need to add!
As you can see from the echo that prints the command about to be run, for some reason the first part is stripped.
Am I missing something in terms of escaping or piping?
Thank you in advance!