From ae018d040423aa68ee0ee4fc949fe70613669c42 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 3 May 2020 12:17:57 -0700 Subject: [PATCH] Created SC2260 (markdown) --- SC2260.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 SC2260.md diff --git a/SC2260.md b/SC2260.md new file mode 100644 index 0000000..a40ca4e --- /dev/null +++ b/SC2260.md @@ -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! \ No newline at end of file