I recently saw this SO answer
Bash natively supports tcp connections as file descriptors. To use:
exec 6<>/dev/tcp/ip.addr.of.server/445 echo -e "GET / HTTP/1.0\n" >&6 cat <&6
I'm using 6 as the file descriptor because 0, 1, 2 are stdin, stdout, and stderr. 5 is sometimes used by Bash for child processes, so 3, 4, 6, 7, 8, and 9 should be safe.
What I don't understand and have never seen before is the exec 6<>
in the first line. What does that mean (given that 6
can presumably be any generic file descriptor, as discussed in the quote)? Particularly I don't recall ever seeing <>
in a bash script before.
Apologies if this is a FAQ, but my usual search engines either don't record or refuse to search for <>
.