2 ms·
>Some great contributions here ... Agreed. >bc -l - the -l option really empowers this awesome little calculator. Right. Since bc is a Unix filter, you can a
by vram22 8y ago
>Some great contributions here ...
Agreed.
>bc -l - the -l option really empowers this awesome little calculator.
Right. Since bc is a Unix filter, you can also pipe expressions into it, to be evaluated, so it can be used in general Unix pipelines. E.g.:
echo *arithmetic_expression* | bc -l
and the output comes on stdout, so it can be further piped.
Edit: You have to quote any shell special characters in arithmetic_expression with single quotes, or better, just enclose the entire arithmetic_expression in single quotes. If asterisk (for multiplication) is not quoted, for example, it will be treated as a filename wildcard instead, and likely lead to an error. A wrong and a right example:
$ echo 2 + 3 * 4 | bc -l
(standard_in) 1: syntax error
$ echo '2 + 3 * 4' | bc -l
14