From c3a5e3d5ba785524d0a14474d79fc8a8bd661e02 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 7 Sep 2020 20:38:00 -0700 Subject: [PATCH] Created SC3022 (markdown) --- SC3022.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 SC3022.md diff --git a/SC3022.md b/SC3022.md new file mode 100644 index 0000000..387b0b4 --- /dev/null +++ b/SC3022.md @@ -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!