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.
Though this is implemented in bash itself and only works in bash, not in other programs.
Re:Projected File System
by meinheld111 on Thursday February 22, 2024 @10:13AM
(#39468268)
The number of unix environments w/o bash available is surprisingly small thou
Re:Projected File System
by proaralyst on Thursday February 22, 2024 @10:48AM
(#39468829)
It means you can't just call open('/dev/tcp/blah') from a program and get a TCP socket though, unfortunately
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.
Although I feel guilty because that's probably more the Plan 9 philosophy. On Linux you get a lot of nice things by having /procfs for example but lots of things aren't files that might be. I've often wondered if a file based interface to dbus wouldn't be very liberating from the scripting point of view for example.
Plan 9 even does sockets via a file based interface and to my eyes it's no more clunky than BSD sockets - but presto, any bash script would be able to open a socket without netcat.