Hi ,
I am doing some enhancements in an existing shell script. There it used the awk command in a function as below :
float_expr() {
IFS=" " command eval 'awk "
BEGIN {
result = $*
print result
exit(result == 0)
}"'
}
It calls the function float_expr to evaluate two values , calculated and returned from the program like below :
if float_expr "$Amount1 != $Amount2" > /dev/null; then
echo "AMOUNTS ARE NOT EQUAL" >> $LOGGEN/${PGM}.log
Stat=1
allstat=1
fi
Amount1 is 9995890.9600 and Amount2 is 9995890.96. In a seperate call Amount1 and Amount2 are passesd as 12851 and 12851.
Now if I run the entire script where the values passed in the funtion via the variable it returns the error :
awk: The string cannot contain a newline character.
The source line is 3.
The error context is
result = eval awk " >>>
<<<
syntax error The source line is 4.
awk: The statement cannot be correctly parsed.
The source line is 4.
However, I ran the same funtion in a stand alone script by passing the two values as hardcoded and it ran fine.
I am not understanding, why this has been happening and need to know a sollution to it.
I need your help on this.