Coding⏱️ 2 min read📅 2026-05-31

How to Fix: How do I write standard error to a file while using "tee" with a pipe?

Write standard error to a file while using tee with a pipe.

Quick Answer: Use the -a option with tee, like this: ./aaa.sh | tee -a bbb.out 2>&1

To write standard error to a file while usingtee with a pipe, you can use the following command:

🔍 How to Do It

  • Use tee with the -a option, which appends output to the file instead of overwriting it:./aaa.sh | tee -a bbb.out 2>&1
  • Alternatively, use tee and pipe both standard error (2>&1) and standard output (1>&1) to the same file:./aaa.sh | tee bbb.out 1>&1 2>&1
  • Or, use a combination of tee, |, and cat to achieve the same result:./aaa.sh | tee ccc.out; cat ccc.out

🛠️ Step-by-Step Verified Fixes

Method 1: Using tee -a

  1. Step 1: Run the command ./aaa.sh | tee -a bbb.out 2>&1

Method 2: Using pipes and redirection

  1. Step 1: Run the command ./aaa.sh | tee bbb.out 1>&1 2>&1

🎯 Final Words

By following these methods, you can write standard error to a file while using tee with a pipe.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions