mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC3022 (markdown)
26
SC3022.md
Normal file
26
SC3022.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
## In POSIX sh, named file descriptors is undefined.
|
||||||
|
|
||||||
|
(or "In dash, ... is not supported." when using `dash`)
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
exec {n}> "$output"
|
||||||
|
echo "Your fd is $n"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
There is no simple, mechanical alternative for POSIX sh, but you can either switch to a shell that does support this (like `bash`), or hard code (or `eval`) a specific file descriptor.
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
The syntax for opening an arbitrary file descriptor and assigning it to a variable for later use is a `bash` and `ksh` extension. It does not work on POSIX sh or `dash`.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user