Is it possible, within a shell script, to write to the screen while STDOUT and STDERR is being redirected?
I have a shell script that I want to capture STDOUT and STDERR. The script will run for perhaps an hour or more, so I want to occasionally write some status messages to the screen that will be displayed and not redirected (not captured).
For a minimal example, I have a shell script, let's say "./myscript.sh":
#!/bin/sh -u
echo "Message A: This writes to STDOUT or wherever '1>' redirects to."
echo "Message B: This writes to STDOUT or wherever '1>' redirects to.">&1
echo "Message C: This writes to STDERR or wherever '2>' redirects to.">/dev/stderr
echo "Message D: This writes to STDERR or wherever '2>' redirects to.">&2
echo "Message E: Write this to 'screen' regardless of (overriding) redirection." #>???
Then, for example, I'd like to see this output when I run the script like this:
[~]# ./myscript.sh > fileout 2> filerr
Message E: Write this to 'screen' regardless of (overriding) redirection.
[~]# ./myscript.sh > /dev/null 2>&1
Message E: Write this to 'screen' regardless of (overriding) redirection.
[~]#
If this cannot be done "directly", is it possible to temporarily discontinue redirection, then print something to the screen, then restore redirection as it was?
Some info about the computer:
[~]# uname -srvmpio
Linux 3.2.45 #4 SMP Wed May 15 19:43:53 CDT 2013 x86_64 x86_64 x86_64 GNU/Linux
[~]# ls -l /bin/sh /dev/stdout /dev/stderr
lrwxrwxrwx 1 root root 4 Jul 18 23:18 /bin/sh -> bash
lrwxrwxrwx 1 root root 15 Jun 29 2013 /dev/stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root 15 Jun 29 2013 /dev/stdout -> /proc/self/fd/1
echo msg > /dev/tty
echo msg > /dev/tty
. That worked! I was sure I tried this early on without success but I must have just tried other similar things. In any case it's working for me. If you'd like to put this as an answer, I'll mark it as accepted.