6

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?

CJ Virtucio
  • 315
  • 1
  • 4
  • 12

1 Answers1

-2

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?

  • That doesn't answer the question. If sqlplus doesn't distinguish between error messages (sending them to STDERR) and normal output (sending it to STDOUT), no clever hack using redirection in the shell can fix this. – Frank Schmitt Jan 04 '21 at 13:58