Categories
dba linux unix

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

The return code is 0 🙂

By Laurent Schneider

Oracle Certified Master

6 replies on “return code before grep”

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
)
)4>&1

Leave a Reply

Your email address will not be published.