Suggestion to replace a part of script

I have the part of script:

    if  [ -f  $tmp_file ]; then
        make_command="make -f  $temp_file"
        print $make_command;
        err\_file="$\{sym_objdir\}error.log"
        $make_command 2>$err_file; cat $err_file;
        [[ -f $err_file ]] && [[ -s $err_file ]] && exit 1;
        exit 0
    fi

Question is very simple.
By means of the above piece of script I am returning exit code as 1 on error. But if you see I am generating a file(err_file="${sym_objdir}error.log") to do so.
My requirement is to the keep the functionality same but avoid the use of $err_file.

Can some give me clue or way to do so?

I think this should suffice:

if [ -f $temp_file ]; then
  make_command="make -f $temp_file"
  print $make_command;
  $make_command 
  exit $?
fi

IMO the blue exit statement can be left out if these are the last statements of your script.

#fd 6 has the same target as STDOUT
exec 6>&1
#STDERR is redirected to fd 1 (which means any errors go straight through to the pipe and trigger exit 1).  if there are no errors, STDOUT is redirected to fd 6, which is now STDOUT
$make_command 2>&1 >&6 | exit 1

this way all you should need is

exec 6>&1
if [ -f $tmp_file ]; then
make_command="make -f $temp_file"
print $make_command;
$make_command 2>&1 >&6 | exit 1
#give fd 1 target of STDOUT again, then close fd 6
exec 1>&6 6>&-
exit 0
fi

see if it works for you.

---------- Post updated at 02:31 PM ---------- Previous update was at 02:28 PM ----------

:b: much simpler way than mine, and here i though i was all clever :eek:

@Scrutinizer
This option I guess will not work with me. Because make is returning some times exit code as 0(success) on errors too. I am not sure about how nor I can change make. So In my piece of code I am making sure that after meeting any kind of error while running make_command. I should be retuning exit code as 1.

The solution provided by you has assumption that make is retuning 1 on error and 0 on success but its not like that as mentioned above.

I see, something like this then?

if [ -f $temp_file ]; then
  make_command="make -f $temp_file"
  print $make_command
  err=$($make_command 2>&1 1>/dev/tty)
  if [ -n "$err" ]; then
    printf "$err\n"
    exit 1
  fi
fi

so you want to exit if there are any errors?

see if what i wrote works, it will directly pipe STDERR to exit 1, so any errors that pop up should trigger it immediately