what is the meaning and usage of 2>&1 | tee /dev/stderr
2
votes
2
answers
473
views
for the following command
output=$(cat $file | docker exec -i CONTAINER COMMAND 2>&1 | tee /dev/stderr)
what is the meaning and usage of 2>&1 | tee /dev/stderr?
I google and 2>&1 means "combine stderr and stdout into the stdout stream."
tee mean "reads from standard input and writes to standard output and one or more files simultaneously."
but I cannot understand if combine
2>&1 | tee /dev/stderr
1) this combine stderr and stdout into the stdout stream, but then again write it to /dev/stderr (&2) again?
2) why need to combine to stdout, then redirect back to stderr?
3) and after write to /dev/stderr, will the message save to variable output in the following?
output=$(cat $file | docker exec -i CONTAINER COMMAND 2>&1 | tee /dev/stderr)
Asked by user1169587
(133 rep)
Feb 19, 2025, 07:35 AM
Last activity: Feb 20, 2025, 09:06 AM
Last activity: Feb 20, 2025, 09:06 AM