It's simple to redirect stdout and/or stderr to a file from within a script with, e.g. "exec 1>/tmp/outfile 2>&1". But if I want later in the script to return one or both to default (the screen), is there a way to do that?
Printable View
It's simple to redirect stdout and/or stderr to a file from within a script with, e.g. "exec 1>/tmp/outfile 2>&1". But if I want later in the script to return one or both to default (the screen), is there a way to do that?
How about this?
Edit: see this informative stackoverflow threadCode:#!/bin/bash
exec 1>/tmp/logfile.txt 2>&1
echo hi logfile
echo errors to logfile too >&2
exec >/dev/tty 2>&1
echo hi tty
echo errors to tty too >&2
Thanks much, Atreyu. I'm scripting to do CIS Red Hat EL5 benchmark hardening on our installed base, and I'm seeing spots from writing awk expressions for days. /dev/tty had plumb eluded me.