Skip to content
Vidar Holen edited this page Sep 8, 2020 · 1 revision

In POSIX sh, /dev/{tcp,udp} is undefined.

(or "In dash, ... is not supported." when using dash)

Problematic code:

echo foo > /dev/tcp/myhost/1234

Correct code:

Rewrite using a tool like netcat (nc):

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!

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally
You can’t perform that action at this time.