Is there a way to configure sqlplus to output errors to STDERR instead of STDOUT?

Viewed 557

If I pipe this script:

me:~/git/my-project$ find . -type f -not -path '*bin*' -name '*ignored*sql' -exec cat {} \;
dsadadasda SELECT * FROM some_table;

into sqlplus like this:

me:~/git/my-project$ find . -type f -not -path '*bin*' -name '*ignored*sql' -exec cat {} \; | sqlplus $my_connection_string | grep -i unknown
SQL> SP2-0734: unknown command beginning "dsadadasda..." - rest of line ignored.

then the error goes into STDOUT instead of STDERR:

me:~/git/my-project$ find . -type f -not -path '*bin*' -name '*ignored*sql' -exec cat {} \; | sqlplus $my_connection_string 1>/dev/null
me:~/git/my-project$

Is there any way to configure sqlplus to do otherwise?

1 Answers

I'd like to quote Manoj here:

File descriptor 1 is the standard output (stdout).
File descriptor 2 is the standard error (stderr).

Here is one way to remember this construct (although it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as "redirect stderr to a file named 1". & indicates that what follows and precedes is a file descriptor and not a filename. So the construct becomes: 2>&1.

Consider >& as redirect merger operator.

Referring link to the source: In the shell, what does " 2>&1 " mean?

Related