Ask coding questions

← Back to all posts
Does the 'bc' calculator function not work here on repl?
Justtocode (1)

A beginner bash coder here. Was trying out arithmetic operation on decimal numbers with ' | bc ' command option. This results in an error, saying bc command not found. What is the way out?

Comments
hotnewtop
DynamicSquid (4621)

You can't have decimals in bash, but you can sue some trickery:

echo $(( 100 * 1 / 3 )) | sed 's/..$/.&/'

Check this SO question for more information. Hope it helps :)

CodeLongAndPros (1596)

install-pkg bc dc.

I like dc, but it's postfix notation.

Justtocode (1)

Hi. Thanks for the reply. It got installed but it still says
expr: non-integer argument with floating point [email protected]

CodeLongAndPros (1596)

@Justtocode You need to do:

echo "$1 + $2" | bc