Bash Scripting Patterns and Practical Recipes/Mirror output to screen and file

Write output to terminal and log file.

Section: Logging and Output

Mirror output to screen and file

bash
bash
./deploy.sh 2>&1 | tee deploy.log
Explanation

Great for CI logs and manual runs.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Logging and Output
Simple log function
Print timestamped log lines.
OpenIn sheetbashsame section
Warn and error helpers
Use reusable stderr helpers for diagnostics.
OpenIn sheetbashsame section
Portable Bash shebang
Use env to locate Bash on PATH.
Create temp file
Create a secure temporary file.
Retry command with delay
Retry a command several times before giving up.
Get script directory
Resolve the directory of the current script.