mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2260 (markdown)
27
SC2260.md
Normal file
27
SC2260.md
Normal file
@@ -0,0 +1,27 @@
|
||||
## This redirection overrides the output pipe. Use 'tee' to output to both.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
env > environment.txt | grep '^ANDROID'
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
env | tee environment.txt | grep '^ANDROID'
|
||||
```
|
||||
|
||||
### Rationale:
|
||||
|
||||
A process only has a single standard output stream. Pipes and output redirections both overwrite it, so you can't use both at the same time. If you try, the redirection takes precedence and the output pipe is closed.
|
||||
|
||||
If you want to dump output to a file while also piping it, use `tee` as in the example.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
None.
|
||||
|
||||
### Related resources:
|
||||
|
||||
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user