Hi All,
I have an expression as follows:-
a=`expr ${i} + ${j}` >> $log_file 2>&1
Here, if any of the values i or j or both happens to be empty then the "expr" returns error as
"expr: 0402-050 Syntax error." My problem is I am not able to re-direct this error to the log file. Its is getting displayed
on the console itself which I don't want to. Any help please.....
OK, first thing first, you're also trying (in a syntactically incorrect way) to append STDOUT to the log too (which would never actually assign anything to the variable.... if the whole thing was enclosed in backticks... ).
I believe that you want this:
a=`expr ${i} + ${j} 2>>${log_file}`
Cheers
ZB
Thanks zazzybob
It worked for me. I did the following:-
a=`expr ${i} + ${j} >> $log_file 2>&1`
Now the error is going to the log file and not to the console. But please tell me what is wrong with the way I am doing for >> $log_file 2>&1. I want to append both the output as well as any errors to the log file. Please correct me if I am wrong.
But you also want to assign to a variable, correct?
a=`( expr $i + $j | tee -a $log_file ) 2>> $log_file`
Now, STDOUT goes to the $log_file, and is stored in the variable. STDERR is appended to the logfile.
Cheers
ZB
You are right zazzybob. I got carried away!!
The variable "a" was not getting populated with the value returned by the expression, with my code.
Your code just works perfect. Once again Thanks.