How to ignore error in command in bash script?

Hello,

i have bash script where im cycling some command for different lines in external file.

example:

while read domain;do
nslookupout=$(nslookup -type=ns $domain) || true
another commands
done < filenamewithdomains

i added:
|| true

after the command in belief it will just skip failures.

But i got:
nslookup: '.somedomain.com' is not a legal name (empty label)

and it breaken running the script..

please how to achieve so this error is skipped and continuing to the next entry?

i know i can fix my domain list so it dont contains inproper values, but i prefer skipping invalid entries. if anyone know how to remove lines in a file containing two dots at one line by sed, please kindly share.

You can do something like this

your command 2>&1 >/dev/null

I don't see, why your code should not work. The || true even takes care of the situation when the shell's -e option is in effect (assuming another command is not failing while -e is in effect).

However, all entries in the filenamewithdomains should not start with a dot.

You could try...

<your initial code>
set +e
nslookupout=$(nslookup -type=ns $domain) || true
set -e
<your final code>

To remove lines with two or more dots, you can use

sed '/\..*\./d' <input >output

and lines with any characters and two or more dots in it?

sed '/\..*\./d' <input >output

works for more than two dots too.