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