mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC3025 (markdown)
31
SC3025.md
Normal file
31
SC3025.md
Normal file
@@ -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!
|
Reference in New Issue
Block a user