TIL: provides pseudo devices for TCP and UDP connections:

echo "hello" > /dev/udp/127.0.0.1/1337

or

exec 5<>/dev/tcp/www.google.com/80
echo -e "GET / HTTP/1.0\n" >&5
cat <&5

I'm baffled how I've never discovered that until today.

@fribbledom oh this is bash? i thought it was the kernel that provided that
Follow

@nik

I don't think it is the kernel... unless those udev rules only apply to bash for some weird reason.

Just did a quick test trying that in zsh and it failed.

· · Web · 1 · 0 · 2

@fribbledom @nik starting bash, your second command works, but `ls /dev/tcp` or `/dev/udp` yields nothing, maybe that's why you didn't notice?

Seems like a rather irregular thing to do tbh.. But then i wouldn't know.

@jasper

Yeah, it's pretty undiscoverable as a user, I'd say.

The first command probably works, too. It's not supposed to output something, it just sends a UDP message to your localhost, port 1337.

@nik

@fribbledom Special handling of certain file names is for redirections, and it is a Bash feature.

"Bash handles several filenames specially when they are used in redirections, as described in the following table. If the operating system on which Bash is running provides these special files, bash will use them; otherwise it will emulate them internally..."

gnu.org/software/bash/manual/h

@jasper @nik

@sajith @fribbledom @jasper @nik can confirm it's bash, does not work in #zsh… unfortunately… 😢

Sign in to participate in the conversation
Mastodon

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!