1
$ echo 2*1024|bc
20480
$ echo 2.0*1024|bc
2048.0
$ echo 2*1024.0|bc
2048.0

What's going on here then?

Update:

dc manages fine

$ echo "2 1024 * p"|dc
2048
oKtosiTe
  • 9,408
  • 9
  • 46
  • 70
Stephen Paulger
  • 197
  • 1
  • 8

1 Answers1

5

If you put the bc sum (2*1024) in single quotes (') does it make a difference? It could well be that the shell is interpreting the * as a wildcard and expanding it in some way.

$ echo '2*1024' | bc

should give you better results.

Majenko
  • 32,128
  • 4
  • 61
  • 81