echo to stderr and tee to log file?

前端 未结 4 1602
青春惊慌失措
青春惊慌失措 2020-12-16 14:52

In bash script,

echo \"error\" 1>&2 | tee -a log

will print stderr in screen but no log to file, how to do these at same tim

4条回答
  •  囚心锁ツ
    2020-12-16 15:35

    echo "error" 1>&2 | tee -a log
    

    With the first part 1>&2, what you are saying is: "Redirect stdout to stderr". So the echoed output "error" goes to stderr.

    Pipe (|) only reads from stdout, not stderr. So tee doesn't get any stdin at all from the pipe. Hence, it appends nothing to the log file.

提交回复
热议问题