I'm working on a script that ssh's into hosts and then sudo's to a privileged user. Since our hosts do not allow sudo with non-tty sessions, pseudo-tty is enabled.
pseudo-tty automatically redirects all STDERR output to STDOUT. This is causing a litany of issues for the project, as dependent libraries do not handle STDERR output well.
Is it possible to undo the STDERR -> STDOUT output redirect? In other words, is it possible to globally mandate that all STDERR output not be sent to STDOUT? I know it's possible to do on a per-command basis, but I'm looking for a way to do this that only has to be done once - ideally when ssh'ing to the host.
You can't "undo" a redirection, but you can redirect somewhere else.
A "bare" redirection in a shell script (eg, 2>/dev/null
) on a line by itself will redirect stdout or stderr for the shell itself and so for all future commands the shell runs.