There are a number of reasons.
First off, your version of nc seems to be different from mine. Mine doesn't have the "-d" option. Then, my server answers with:
Code:
homeserv.megaline.com [192.168.110.10] 22 (ssh) open
Other than that, it seems that the respons of nc is not written to stdout but to stderr:
Code:
jlinkels@donald-pc:/mnt/homeserv/home/applic/docs/misc/recepten$ var1=$(nc -vzw5 homeserv.megaline.com 22)
homeserv.megaline.com [192.168.110.10] 22 (ssh) open
jlinkels@donald-pc:/mnt/homeserv/home/applic/docs/misc/recepten$ echo $var1
<empty line>
Then if the output of nc was assigned to $var1, it would contain a CRLF at the end, whereas $var2 doesn't have that. You should check on a part of the return string, not on the entire string.
It would be much better to check the result of the nc command by examining the $? variable. It returns 0 on success and 1 on failure of nc.
jlinkels