I tried this:
file="myfile"
while read -r line
do
[[ $line = \#* ]] && continue
"address=\$line\127.0.0.1"
done < "$file"
This code doesn’t avoid the lines that begin with comments. Even if I don’t have any comments, dnsmasq tells that there are errors.
Its going to be a dnsmasq conf file, and it will read and insert domain names like so: address=\mydomain.com\127.0.0.1.
EDIT:1
Input file:
domain1.com
domain2.com
domain3.com
#domain4.com
domain5.com
Output should be:
address=/domain1.com/127.0.0.1
address=/domain2.com/127.0.0.1
address=/domain3.com/127.0.0.1
address=/domain5.com/127.0.0.1
I will drop the script in /etc/dnsmasq.d/ directory so that dnsmaq.conf can process it when dnsmasq is started.
It’s safer to use
[[ "$line" = "\#*" ]]Btw,
address="\\${line}\\127.0.0.1"UPD:
If I’ve understand you right you need to change every uncommented domains to
address=\domain\127.0.0.1. It could be done fast and easy withsed, there is no need in bash-program.If you need to remove commented lines, sed can do it too with
/matched_line/dUPD2: if you want to do all that stuff inside the bash script, here is your code modification:
And it’s output: