TEST1=`echo $QUERY_DAYS3 | awk '{print $1}'`
echo $TEST1
TEST2=`echo $QUERY_DAYS3 | awk '{print $2}'`
echo $TEST2
mailx -s "Data Report" -r [email protected] [email protected] <<EOF
Error Percentage: $((100 * ($TEST2/ $TEST1)))
EOF
In my bash Shell script I have the above code from which I am sending email. But when I check my email I always see Error Percentage written like as it is written in my above code. It is not evaluating the multiplication and division expression.
I am running the above script like this-
sh -x test1.sh
In the email I get like this-
Error Percentage: $((100 * (183563 / 3793277)))
I am running SunOS.
May be I need to use Back-Ticks here?
Update:-
My updated script that I am using currently-
TEST1=`echo $QUERY_DAYS3 | awk '{print $1}'`
echo $TEST1
TEST2=`echo $QUERY_DAYS3 | awk '{print $2}'`
echo $TEST2
mailx -s "Data Report" -r [email protected] [email protected] <<EOF
Error Percentage: $(( 100 * $TEST2 ) / $TEST1)
EOF
I am running it like this below-
sh -c 'exec ./test.sh'
After trying the suggestion given by lot of peoples. I am getting this error-
./test.sh: command substitution: line 176: syntax error near unexpected token `/'
./test.sh: command substitution: line 176: `( 100 * $TEST2 ) / $TEST1'
What wrong I am doing now? Any thoughts?
Update:-
After making changes, it start working-
Mismatch Percentage: $((( 100 * $TEST2 ) / $TEST1))
But in the email, the percentage I get was rounded to only one figure like 4 only instead of showing as 4.34563235 How can I get full numbers instead of getting rounded off to one digit.?
( 100 * $TEST2 ) / $TEST1in there, otherwise you'll always get a percentage rounded to zero.bashis used as the shell? What doesecho $SHELLgive?echo $SHELLgives me this/bin/sh.../bin/shis Bourne shell, notbash, at least up to Solaris 10...