From 8e711c85ae76fc405797e2b2e66b2b6697b653ae Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 6 Dec 2020 21:02:39 -0800 Subject: [PATCH] Created SC1142 (markdown) --- SC1142.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 SC1142.md diff --git a/SC1142.md b/SC1142.md new file mode 100644 index 0000000..ae88f0a --- /dev/null +++ b/SC1142.md @@ -0,0 +1,36 @@ +## Use 'done < <(cmd)' to redirect from process substitution (currently missing one '<'). + +### Problematic code: + +```sh +sum=0 +while IFS="" read -r n +do + (( sum += n )) +done <(file) +``` + +### Correct code: + +```sh +sum=0 +while IFS="" read -r n +do + (( sum += n )) +done < <(file) +``` +### Rationale: + +ShellCheck found a `done` keyword followed by a process substitution, e.g. `done <(cmd)`. + +The intention was most likely to redirect from this process substitution, in which case you will need one extra `<`: `done < <(cmd)`. + +This is because `<(cmd)` expands to a filename (e.g. `/dev/fd/63`), and you need a `<` to redirect from filenames. + +### Exceptions: + +None + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file