Thursday, October 14, 2010

Command line calculator

Esta no terminal e precisa fazer uma conta rápida... use o comando bc do unix

On line examples
echo "56.8 + 77.7" | bc

echo "obase=16; ibase=10; 56" | bc

echo "scale=6; 60/7.02" | bc

echo 2/5 | bc -l

bc -l <<< "(0.5/150)*100"

Interactive mode Example
bc (enter)
1+1
>2
last+2 ; last indica ultimo resultado.
>4
last + 5
>9
last +8
>17
quit


Script solve.sh para facilitar o uso

#!/bin/sh

bc << EOF
scale=4
$@
quit
EOF


$ sh solve.sh 1+1
2
$ sh solve.sh 11/7
1.5714



http://www.linuxjournal.com/article/9891

No comments:

Blog Archive