I'm doing some audit automation, this example describes checking the version of Java, even though other programs do the same thing.
The output of "java -version" goes to STDERR, which is easily redirected, but I want to send shell errors (for example, when the java binary is missing) to /dev/null. It seems that shell redirection is an all-or-nothing proposition.
My most promising attempt so far as been:
{ /bin/ksh "{java -version 2>&1;}"; } 2>/dev/null
...which properly sends the output of the -version command to STDOUT, but if java isn't there, it sends the shell "not found" error to STDOUT as well. I don't want to see that message.
Same behavior with:
{ /bin/ksh "{java -version 2>&1;}" 2>/dev/null; }
Does anyone know a way to limit the scope of redirection so each process gets its own? I'm not limited to ksh, but for environment reasons it's got to be a shell based one-liner.