Error re-direction and Return code

Hi,

I have a shell script which executes some sql. When the shell script executes the sql's logging is shown on the console. I need to grep some data from this output shown on console. So I do the following

hive -f load.adj.hql 2>&1 | tee c.txt
echo $?
A=`grep num_rows c.txt`

$? will again always be 0 whether load.adj.hql passes or fails.
How do I make $? reflect status of hive -f load.adj.hql BUT also capture output on console?

---------- Post updated at 12:30 PM ---------- Previous update was at 12:22 PM ----------

I got the answer

echo ${PIPESTATUS[0]}
1 Like

Thanks for the answer. Note to others reading this post: The ${PIPESTATUS[0]} is an arra6y of return code for each process in a pipe - a bash shell builtin.

1 Like