Run multiple commands in $() without opening a new shell

The code below works, but takes too many lines and looks awkward:

        db2 "export to $filename of del select * from $table with ur"|tee -a $LOGFILE|awk '/Number of rows exported:/ {print $5}' > numrows.tmp
        numrows=$(cat numrows.tmp)
        rm numrows.tmp

When I try the statement below instead, I get a message saying there's no connection to the database. That's because it opened a new shell. It's opening a new shell when I give more than just the db2 command. How can I get the code below work:

numrows=$(db2 "export to $filename of del select * from $table with ur"|tee -a $LOGFILE|awk '/Number of rows exported:/ {print $5}' )

Thanks in advance
Naveen

You can read the value like this:

db2 "export to $filename of del select * from $table with ur"|tee -a $LOGFILE|awk '/Number of rows exported:/ {print $5}' | read numrows

numrows variable is not getting anything assigned by read.