Can you redirect STDERR to the entire Bash session?

There are many questions about the referral stderrand stdoutto a single command or script. I would like to redirect any stderr messages from my Bash session to a log file.

I need an interactive Bash session where everyone is stderrredirected to a file.

+4
source share
3 answers

Awful way to solve your problem:

exec 3>&2
trap 'exec 2>>/path/to/your_file' DEBUG
PROMPT_COMMAND='exec 2>&3'
  • exec 3>&2: we first copy fd 2 to the new fd (here fd 3)
  • trap 'exec 2>/dev/null' DEBUG: ( ​​ extdebug, ), DEBUG : stderr /path/to/your_file (, ).
  • Bash PROMPT_COMMAND: fd2 fd3 ( fd3 - fd2, ). , .

, .

+5

.

exec 2> elsewhere

.

0

, , . STDERR STDOUT STDERR :

eval $1 2>&1 >>~/max.log | tee --append ~/bash.log
-4

Source: https://habr.com/ru/post/1609812/


All Articles