From b8839ea6d320f08a0b327247d8d545cdcc5d1a5e Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 7 Sep 2020 20:24:59 -0700 Subject: [PATCH] Created SC3025 (markdown) --- SC3025.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 SC3025.md diff --git a/SC3025.md b/SC3025.md new file mode 100644 index 0000000..d645fca --- /dev/null +++ b/SC3025.md @@ -0,0 +1,31 @@ +## In POSIX sh, /dev/{tcp,udp} is undefined. + +(or "In dash, ... is not supported." when using `dash`) + +### Problematic code: + +```sh +echo foo > /dev/tcp/myhost/1234 +``` + +### Correct code: + +Rewrite using a tool like netcat (`nc`): + +```sh +echo foo | nc myhost 1234 +``` + +### Rationale: + +`/dev/tcp/$host/$port` and `/dev/udp/$host/$port` are recognized in redirections by bash and ksh, and a socket connection is made instead of opening a file. They do not physically exist in `/dev`. + +POSIX sh and dash do not support this, so any such code should be rewritten to use a socket tool explicitly. The obvious candidate is netcat aka `nc`. + +### Exceptions: + +None + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!