Search code examples
linuxbashunixfloating-pointbc

Bash Doesn't Support Floating Point Operations — But Why Can I Use BC?


I read from a passage that

Unlike most programming languages, BASH does not have builtin floating point math (it does have builtin integer math, however).

However, I can still do

echo "5.0>5.9" | bc -l
0

echo "5.0+5.9" | bc -l
10.9

These are floating point numbers; why does bc still work in these situations?


Solution

  • The Unix utility bc is not part of Bash. The echo produces characters on its standard output; bc takes its standard input and performs math operations. All that bash is doing in this case is stringing together the standard output to standard input implied by the | operator.