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.
#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 ----------
much simpler way than mine, and here i though i was all clever
@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.
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