TEST1=`echo $QUERY_DAYS3 | awk '{print $1}'`
echo $TEST1
TEST2=`echo $QUERY_DAYS3 | awk '{print $2}'`
echo $TEST2
mailx -s "Data Report" -r uname@host.com uname@host.com <<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 uname@host.com uname@host.com <<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.?
You can’t expect it to run under bash, if you explicitely tell
shto execute it…Try
Having
as the first line, will only work if you directly execute the script:
It needs to be ‘executable’ for that to work
Update
needs to be