I am new to bash shell scripting and facing a problem.
I have code like this:
function build()
{
echo "Building: " | tee -a $LOG_FILE
{
#do some processing here and if error set the err var to say 2
if [[ $err -eq 2 ]]; then
echo "Error: exit"
exitStatus=2
fi
} 2>&1 | tee -a $LOG_FILE | grep -e "$GREP_FAIL_TERM" -e "$GREP_ERROR_TERM"
}
where
GREP_FAIL_TERM='[Ff]ail'
GREP_ERROR_TERM='[Ee][Rr][Rr][Oo][Rr][,;:\ ]'
and
exitStatus is a global variable set to 0 at the beginning of script
When I come out of this function in case of error and check the value of exitStatus it is 0. I read that using | executes the command in subshell which is not reflected in parent. But then, how can I execute the above code while outputting to log file.