Results 1 to 4 of 4
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-19-2012 #1
Bash: Redirect stdout/stderr to file, then back to screen?
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?
- 11-19-2012 #2Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,680
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
Last edited by atreyu; 11-19-2012 at 11:55 PM. Reason: link
- 11-20-2012 #3
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.
- 11-20-2012 #4Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,680


Reply With Quote

