user1431282
user1431282

Reputation: 6845

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?

Upvotes: 0

Views: 160

Answers (2)

Abrixas2
Abrixas2

Reputation: 3295

The expressions 5.0>5.9 and 5.0+5.9 are sent to bc, which is a stand-alone program.

Upvotes: 3

GoZoner
GoZoner

Reputation: 70245

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.

Upvotes: 5

Related Questions