return code before grep

In my previous post hide-password-from-ps-output-sql-loader I mentioned a way to pass the password to the loader thru a parameter file. As correctly suggested by Brian Tkatch, the password could be passed as standard input

sqlldr control=x.ctl silent=header,feedback <<EOF
scott/tiger
EOF
Username:

The Username: prompt is displayed :(   :(

How do we get rid of this ?

sqlldr control=x.ctl silent=header,feedback <<EOF | grep -v "^Username:"
scott/tiger
EOF

There is no output. But what’s the error code

echo $?
1

The return code is 1 :(

This is not the error code from sqlldr, but the error code from grep !

Ok, here is the trick, a bit cryptic if you are not familiar with file descriptors

( ( (sqlldr control=x <<EOF;echo $? >&3) |grep -v "^Username:" >&4 ) 3>&1 |(read x;exit $x) )4>&1
scott/tiger
EOF
echo $?
0

The return code is 0 :)

6 thoughts on “return code before grep”

  1. Yes, that is very true, but the file may be backup up and kept in unsafe place, you never know ;-)

    Standard input is still safer as not saved to a filesystem

  2. I’m a bit confused as to what exactly should go in the calling script here? I see mismatched parentheses in the example. Am I missing something?

  3. @Frank : due to EOF, it must be on one line…

    try this

    (
      (
        (
          echo scott/tiger | sqlldr control=x
          echo $? >&3
        ) |
          grep -v "^Username:" >&4 
      ) 3>&1 |
        (
          read x
          exit $x
        ) 
    )4>&1
    

Leave a Reply

Your email address will not be published.


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>