Skip to content
Vidar Holen edited this page May 3, 2020 · 2 revisions

This redirection overrides the output pipe. Use 'tee' to output to both.

Problematic code:

env > environment.txt | grep '^ANDROID'

Correct code:

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!

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally