Multiplication on command line terminal Ask Question

Multiplication on command line terminal Ask Question

I'm using a serial terminal to provide input into our lab experiment. I found that using

$ echo "5X5"

just returns a string of "5X5". Is there a command to execute a multiplication operation?

ベストアンサー1

Yes, you can use bash's built-in Arithmetic Expansion $(( )) to do some simple maths

$ echo "$((5 * 5))"
25

Check the Shell Arithmetic section in the Bash Reference Manual for a complete list of operators.

For sake of completeness, as other pointed out, if you need arbitrary precision, bc or dc would be better.

おすすめ記事