Using bash, how do you receive using /dev/udp
?
Sending works. It seems weird but I can’t make receive work (even though I think I did it in the past). So, I must be doing something very stupid.
From one session, I send periodic UDP packets:
$ while true; do echo foo >/dev/udp/localhost/5555; sleep 1; done
I see the packets using wireshark and netcat can receive them:
$ nc -ulW1 localhost 5555
foo
$
But redirecting input from /dev/udp/localhost/5555
receives nothing. All the following commands hang without reading anything.
$ cat </dev/udp/localhost/5555
$ read line </dev/udp/localhost/5555
Replacing localhost
with 127.0.0.1
does not change anything. And you may have noticed that sending to /dev/udp/localhost/5555
works.
Please, do not answer “use netcat”. I know netcat works. I want to understand what’s wrong with redirecting input from /dev/udp
.
FWIW, it’s bash version 5.2.21 on Ubuntu 24.04 but it shouldn’t matter anyway.
7