That error message is given by dig
, which I have no experience with. There are no obvious shell syntax errors that I can see. Perhaps you're getting an empty value for "$i
"? In which case you'd need to set up a test first to skip blank entries.
I have however spotted a different error that I missed before.
" sits outside of the loop, "$i
" isn't defined when the redirection is set up, and the resulting filename will be simply ".hosts
" (unless there's a previously-defined value for "$i
", of course, in which case it uses that).
We have to move the redirection inside the loop to get the proper behavior.
while read i; do
[[ -z $i ]] && continue
echo "$i" >>"$i.hosts"
dig -p 54 @192.168.0.3 "$i" axfr >>"$i.hosts"
This should append the output of both commands to a filename starting with the current value of "$i