English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Il comando bc è un linguaggio di calcolo a precisione arbitraria, di solito utilizzato come calcolatore in Linux.
È simile a un calcolatore di base, con questo calcolatore è possibile eseguire operazioni matematiche di base.
Operazioni comuni:
bc(opsione)(parametro)
Valori delle opzioni
Parametri
File: specificare il file che contiene l'operazione di calcolo.
$ bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 2+3 5 5-2 3 2+3*1 5
Enter 'quit' to exit.
Through the pipe symbol
$ echo "15+5" | bc 20
scale=2 Sets decimal places, 2 represents retaining two places:
$ echo 'scale=2; (2.777 - 1.4744)/1' | bc 1.30
bc, in addition to scale for setting decimal places, also has ibase and obase for other base arithmetic:
$ echo "ibase=2;111" |bc 7
Base Conversion
#!/bin/bash abc=192 echo "obase=2;$abc" | bc <pre> <p> The result is: 11000000, which is the decimal to binary conversion using bc.</p> <pre> #!/bin/bash abc=11000000 echo "obase=10;ibase=2;$abc" | bc
The result is: 192, which is the binary to decimal conversion using bc.
Calculate Square and Square Root:
$ echo "10^10" | bc 10000000000 $ echo "sqrt(100)" | bc 10