Append text to stderr redirects in bash

前端 未结 4 1232
青春惊慌失措
青春惊慌失措 2020-12-08 17:09

Right now I\'m using exec to redirect stderr to an error log with

exec 2>> ${errorLog}

The only downside is that I have to start each

4条回答
  •  我在风中等你
    2020-12-08 17:30

    You could simple just use:

    exec 1> >( sed "s/^/$(date '+[%F %T]'): /" | tee -a ${LOGFILE}) 2>&1
    

    This will not completely solve your Problem regarding Prompt not shown (itt will show after a short time, but not realtime, since the pipe will cache some data...), but will display the output 1:1 on stdout as well as in the file.

    The only problem is, that I could not solve, is, to do this from a function, since that opens a subshell, where the exec is useless for the main program...

提交回复
热议问题