Use shell built-in time while checking exit status of a function and suppressing output

bash time is a major PITA. Its output isn't redirectable without nasty shell hacks like your multiple levels of subshells. http://mywiki.wooledge.org/BashFAQ/032 suggests that the correct answer is:

TIME = $( ( time $MYSQL "$1" 2>&1 | tee /tmp/somefile.txt > /dev/null; exit ${PIPESTATUS[0]} ) 2>&1 )

Note that bash time takes an entire pipeline as an argument, so placing the subshell after the time invocation is incorrect.

This was tested with

TIME = $( ( time ls /asdfasfdsfs 2>&1 | tee asdf 2>&1 >/dev/null ; exit ${PIPESTATUS[0]} ) 2>&1 );
echo $?;
echo $TIME

Which gave me

2
real 0m0.003s user 0m0.004s sys 0m0.004s