Sometimes it's all about the aesthetics.


sh/ksh/bash redirecting the stdout and stderr

This seems to belong to "Wizard Level I/O"......orz
Recently g95 croaks some warning on Mac OS X platform like:

% g95 test.f90 
/var/tmp//ccXFPLrz.s:59:indirect jmp without `*' 
It seems to be a known issue and the compiler still builds working binaries (assembly code? not sure). It is reasonable to get a wrapper script that filters out the warning. It turns out to be not as easy as I thought:
exec 3>&1
$myg95 $* 2>&1 >&3 | grep -v "indirect jmp without " 1>&2
exec 3>&-
This duplicates stdout to another file descriptor (3), then runs the g95 command with stderr redirected to stdout and stdout redirected to the saved descriptor (3). The result is piped into filter command to get rid of irreverent errors. The output of the pipeline is redirected back to stderr, so that stdout and stderr of the script as a whole are what it is expected.

No comments: