News for hackers. Stuff that matters.
Re:Sockets in Your Shell by jagged-chisel on Thursday December 03, 2020 @07:07AM (#25288068)
> echo "text!" > /dev/$PROTO/$HOST/$PORT

This being a bash-ism is really misleading. This looks as if my computer has device nodes for $PROTO, and I suppose that's not the case. I think it would make more sense as (optional) /dev nodes giving all programs access to it.

Re:Sockets in Your Shell by dx87 on Thursday December 03, 2020 @08:01AM (#25288396)
The man page for bash says that /dev/tcp and /dev/udp actually can be real files that any program can use, but that if they're absent, it emulates the behavior on its own.
Re:Sockets in Your Shell by duskwuff on Thursday December 03, 2020 @02:27PM (#25293377)
> The man page for bash says that /dev/tcp and /dev/udp actually can be real files that any program can use

But that's really just a bit of wishful thinking -- those files/directories don't exist on any mainstream UNIX OS I'm aware of.

Re:Sockets in Your Shell by who23 on Saturday December 05, 2020 @02:30AM (#25312612)
Hey I'm the author. Yes, as far as I know it's just sugar for opening a socket, and there's almost never a file that exists. To treat it as a file, you need to assign a file descriptor to it, which you can then read and write from.
Re:Sockets in Your Shell by rvense on Thursday December 03, 2020 @09:23AM (#25289059)
Actually, I don't have that device in my normal shell, mksh, but the command works in bash? Is bash putting things in /dev? That seems rather... bad, to be honest.
Re:Sockets in Your Shell by dx87 on Thursday December 03, 2020 @09:40AM (#25289236)
Bash isn't putting anything in /dev. It checks to see if those files exist (I've never seen them actually exist though), and if they aren't there, it just parses the string and creates a network connection as though they did exist.
Re:Sockets in Your Shell by HelloNurse on Thursday December 03, 2020 @12:26PM (#25291560)
Bash is not even pretending such special files exist: /dev/tcp/somewhere is only an elegant syntactic shortcut for requesting a telnet-like network connected pipe in a context in which a filename is required. For the child process, it's just a file descriptor.
Re:Sockets in Your Shell by rvense on Thursday December 03, 2020 @01:21PM (#25292435)
I don't think it's elegant at all. Magically treating special strings in this manner seems like a violation of "everything is a file".
Re:Sockets in Your Shell by _ZeD_ on Thursday December 03, 2020 @08:20AM (#25288526)
how is this a bash-ism? you mean it's related to linux /dev tree?
Re:Sockets in Your Shell by bitwize on Thursday December 03, 2020 @10:48AM (#25289990)
No, it's not related to the actual /dev tree. Bash handles redirects to /dev/tcp/* and /dev/udp/* specially if there are no files at those locations.
Re:Sockets in Your Shell by TheGrassyKnoll on Thursday December 03, 2020 @04:09PM (#25294975)