Bash script scenarios to capture stdout and stderr when using process substitution with `tee`
I'm dealing with I'm refactoring my project and I'm sure I'm missing something obvious here, but I'm trying to execute a command in my Bash script and capture both its stdout and stderr output into a log file while also displaying the output to the console... I thought I could achieve this using process substitution with `tee`, but I'm running into issues. When I run the script, it seems that the stderr is not being captured correctly, and I only see the stdout in my log file. Here is the command I am using: ```bash #!/bin/bash # Sample command that may generate both stdout and stderr command_with_errors 2>&1 | tee >(cat > output.log) ``` When I execute this script, I'm getting the behavior message: "command_with_errors: command not found" but I also see the expected output for stdout. However, the stderr seems to be missing in the `output.log`. I've also tried various combinations like adding `2>&1` in different places, but nothing seems to work. Hereβs a breakdown of what Iβve attempted: - Using just `command_with_errors | tee output.log` - this only captures stdout. - Redirecting stderr before passing it to `tee` - still not capturing stderr. - Trying to run it with bash instead of sh - no change. I am using Bash version 5.0 on Ubuntu 20.04. Can anyone guide to understand how to correctly capture both stdout and stderr in the log file using `tee`? I also want to ensure that I can still view the output in the terminal as it executes. Am I missing something obvious? My development environment is Linux. I'd really appreciate any guidance on this. For context: I'm using Bash on Ubuntu 22.04. Thanks, I really appreciate it! Has anyone dealt with something similar?