tee
A command that copies its standard input both to one or more files and to its standard output.
In more detail
Put it mid-pipeline to keep a snapshot of the data at that point while the pipeline carries on. -a appends instead of truncating. sudo tee is the standard way to write to a root-owned file, because in sudo echo x > file the redirect is opened by your unprivileged shell, not by sudo.
Examples
echo '127.0.0.1 staging.local' | sudo tee -a /etc/hostsbash tests/run.sh | tee reports/report.txtRelated terms
- pipe — The | operator, which connects one command's standard output to the next command's standard input so they run together.
- sudo — A command that runs another command with administrator (root) rights after checking you are allowed to.
- redirection — Sending a command's output into a file instead of the terminal: > replaces the file, >> appends to the end of it.
- test report — A file written by a test run that records which tests passed and failed.
- pipefail — The bash option that makes a pipeline fail if any stage fails, instead of reporting only the last stage's status.
Taught in
- Pipelines, tee And Process Substitution — Bash Scripting & Command Line Automation
- Conditionals: test, Brackets, Double Brackets, case — Bash Scripting & Command Line Automation
- Passing Data Between Jobs: Artifacts — Continuous Integration & Continuous Delivery Pipelines