Howdy,
Can I configure bash on Linux to write a copy of all stdout and stderr to a regular file, without having to specify the redirection for each command?
Thanks, Kent
Howdy,
Can I configure bash on Linux to write a copy of all stdout and stderr to a regular file, without having to specify the redirection for each command?
Thanks, Kent
If you are writing a script, I'd recommend write a shell function and redirect its output. You won't have to redirect each command of that function then. I hardly see any meaning in redirections in interactive shell anyway.
The exec
command, if not given a command to execute, will apply its redirections to the current shell. In my testing, however, this does not seem to work that well for pipes. I'd suggest using a subshell, which you can redirect normally.
(
echo hello
echo hello err >&2
) 2>&1 | tee logfile.txt
If you only need a transcript, not a continuous tee, exec >& logfile
might work.
Also, a traditional trick is to use a remote login tool (ssh or telnet) piped to tee to create a log of an interactive session. screen also supports logging.