0

I know that both of them can do simple arithmetic. I'm wondering when it will be easier to use one versus the other.

I know that expr evaluates an expression from its arguments, while bcl evaluates from standard in, but what other differences are there?

Specifically, are there any tasks that one can perform, but the other can't?

2

Specifically, are there any tasks that one can perform, but the other can't?

For one thing, bc supports big numbers while expr tops out at 2^63-1:

$ expr 9223372036854775807 + 1
-9223372036854775807

$ echo "9223372036854775807 + 1" | bc
9223372036854775808

bc also has exponentiation and square root operations, which expr lacks entirely:

$ echo "2^1024" | bc
17976931348623159077293051907890247336179769789423065727343008115773\
26758055009631327084773224075360211201138798713933576587897688144166\
22492847430639474124377767893424865485276302219601246094119453082952\
08500576883815068234246288147391311054082723716335051068458629823994\
7245938479716304835356329624224137216
$ echo "scale=100; sqrt(2)" | bc
1.414213562373095048801688724209698078569671875376948073176679737990\
7324784621070388503875343276415727

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.