Tobey Tobey - 5 months ago 23
Bash Question

Why is there a difference between the output of a Script and a Terminal Command?

Why does bash change the output of my script in comparison to the terminal output?

If I type

dig +noall +answer NS

I get this

But if I do it with a script

echo "Domain: "
DIG=$(dig +noall +answer NS $DOMAIN)
echo $DIG

I get

I want to have the same results as if I typed the command in the console.

I know I could just save and sort (not exactly sort but awk) them in a file but if possible I want to get the same result without having to save the results in a file.

I'm using Ubuntu 16.04 if that helps you

Answer Source

Quote your variables!

$ DIG=$(dig +noall +answer NS

$ echo $DIG 86308 IN NS 86308 IN NS 86308 IN NS 86308 IN NS

$ echo "$DIG"             86295   IN      NS             86295   IN      NS             86295   IN      NS             86295   IN      NS
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download