As explained here you can use exec
and &>
redirection with tee
to capture standard output and standard error to a file.
One thing I'm wondering about is whether you want to have a different capture per command (as can be understood from your requirement for "every command" and the assertion that script
cannot be used) or whether you just want to capture an entire session in a log file.
If its the latter, then running script
at the beginning of the session and then implementing whatever else you did inside that should work fine, but the above linked answer would also help. If you do want a different file for every command, then you'd probably want to implement something that triggers in the command prompt - possibly by implementing $PROMPT_COMMAND
(man bash
for more details) and replaces the log file for each command.
Please note that as exec &>
captures the standard streams into a file, it basically disables and TTY applications (that draw on the screen) from running (such as less
or mc
). This will be true for any shell level console capture tool, unless it does a full TTY emulation (as script
does, I believe).
script
does not save the exit code of the command IIRC.echo $?
or similar after each command inscript
.script
doesn't save the exit code, but you could add that exit code to your prompt (possibly only when non-zero, which is a very sensible thing to do in any case), so it would then be saved as part of the output.