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 <

The Username: prompt is displayed 🙁   🙁

How do we get rid of this ?

sqlldr control=x.ctl silent=header,feedback <

There is no output. But what's the error code
echo $?

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 <&3) |grep -v "^Username:" >&4 ) 3>&1 |(read x;exit $x) )4>&1
echo $?

The return code is 0 🙂


  • 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

  • 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?

  • @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

Leave a Reply

Your email address will not be published.