can quoted text return values

Hi All,
index=10.5
let "res = $index + 1.7"
echo "res = $res"

Can anybody explain what this piece of code does.

home work ?

No. Got this in one of the books. When i executed this it showed an error but the answer in the book said that it prints a 1. But i am not able to reason out why. Anybody has any clue ?

I guess the output is "11". Instead of "1". I got the below.

TES> cat  rem.sh
index=10.5
let "res = $index + 1.7"
echo "res = $res"

TES>. rem.sh
res = 11

But why is the result 11. Any idea? If only whole number addition is done it should return 12 for 10.5 + 1.7 should yield 12.2 ~ 12.
Is there something special with the quoted expression viz "res = $index + 1.7"

Thanks in advance

For any floating point related operations you might need to use "bc".

Here the quotes wont make any difference, the bash allows you to do

arithmetic using the "let" command. I guess "let" considers only the integer

part.

In short: most shells don't know about floating point operations, and truncate any real numbers to their largest integer part.. In your case, 10.5 gets truncated to 10, and 1.7 to 1. 10 + 1 = 11

Hi Pludi,
Thanks for the xplanation. I think that explained why I got this o/p