Hacker News new | ask | show | jobs
by bytK7 848 days ago
Indeed, bash already has socket access via /dev/tcp/HOST/PORT and /dev/udp/HOST/PORT, which allow opening a socket and reading from/writing to it as if it were an ordinary file.
2 comments

IIRC that only works for clients and can't be used for listening.

Also IIRC there is a bash loadable module that implements server sockets but that can't be relied upon if you're just shipping bash scripts meant to be run without the end user preparing the ground before running it.

I mean, file handlers exist in Linux. That would be so cool if you could add a file/directory watch to an http endpoint/resource
Though this is implemented in bash itself and only works in bash, not in other programs.
The number of unix environments w/o bash available is surprisingly small thou
It means you can't just call open('/dev/tcp/blah') from a program and get a TCP socket though, unfortunately