-1

I have created a file that contains arithmetic expressions, one per line. How can I evaluate the expressions and display the results, from the command line?

The file looks like this:

1 + 2
6 * 4
97 % 12
43215 / 43 * 100

The goal is to output each result, in order, also one per line. I recall there is a way to do this that only requires one command, and that command used might start with w, but I can't remember how.

Melebius
  • 11,750
Ktgvb
  • 77

1 Answers1

10

You can use bc as calculator, and send your file to it as input:

$ cat maths.txt
1 + 2
6 * 4
97 % 12
43215 / 43 * 100

$ bc < maths.txt
3
24
1
100500
wjandrea
  • 14,504
Byte Commander
  • 110,243