(1) BCBC is an interactive instruction by default. In the BC working environment, you can use the following calculation symbols:
+ Addition
-Subtraction
* Multiplication
/Division
^ Index
% remainder
such as:
3+4;5*2;5^2;18/4 <= a line to enter multiple calculations, separated by.
7
10
25
4
Quit <= quit# British
scale=3 <= Set decimal digits
1/3
.333
Quit above is the calculation of the interaction, that can also
Direct calculation of results without interaction。 A. Using the Echo and | method, such as:
# echo "(6+3) * *" |BC
18# Echo 15/4 |BC
3# echo "SCALE=2;15/4" |BC
3.75# echo "3+4;5*2;5^2;18/4" |BC
7
10
25
4 In addition,
BC In addition to scale to set the decimal digits, there are ibase and obase to other binary operations. such as://Will be 16 binary A7 output for 10, note, English can only uppercase # echo "IBASE=16; A7 "|BC
167//2 binary 11111111 into 10 # echo "ibase=2;11111111" |BC
255//input is 16 binary, output is 2 # echo "ibase=16;obase=2; B5-a4 "|BC
10001
for BC, you can also find it in BC--HELP: You can pick up the file name after BC. such as: # more Calc.txt
3+2
4+5
8*2
10/4
# BC Calc.txt
5
9
16
2
2) ExprThe expr command does not calculate subtraction Oh, there are many expressions that can be computed, but one thing to note is that when calculating subtraction, don't forget to use spaces and escapes. The following example is used to describe the operation of expr, such as: # Expr 6 + 3 (with spaces)
9 # expr 2/* 3 (with escape symbol)
6# Expr 14% 9
5 # A=3
# expr $a +5 (no spaces)
3+5
# expr $a + 5 (variable, with spaces)
8# a= ' expr 4 + 2 '
Echo $a
6
# expr $a + 3
9
In addition, expr is also very handy for the operation (calculation) of strings, such as:
//String length
# expr Length "yangzhigang.cublog.cn"
21st
//Grab a string from a location
# expr Substr "yangzhigang.cublog.cn" 1 11yangzhigang
//String starting at# expr Index "yangzhigang.cublog.cn" CU
13
3) DCThere are not many people using DC to calculate, because DC is more complex than BC, but it's pretty much the same when it comes to simple planning. DC is a stack operation, the default is also interactive, but can also use echo and | to match the plan. such as: # DC
3
2+p
5
The
P
20quit # echo 3 |DC p
20
4) EchoEcho is used to echo, it is the week-to-day thing. The above also works with BC to calculate. In fact, Echo can also be a simple calculation, such as: # echo $ ((3+5))
8
# echo $ (((3+5) *))
The echo can also be used to calculate variables such as: # a=10
# b=5
# echo $ (($a + $b))
15
# echo $a + $b
10+5
# echo $a + $b |BC
15//Calculate date of day before # echo ' Date +%y%m%d '
20090813
# echo ' Date +%y%m%d '-2
20090813-2
# echo ' Date +%y%m%d '-2 |BC
20090811
5) AWKWhen awk is working on a file, it can be computed, of course, for example: # awk ' Begin{a=3+2;print A} '
5
# awk ' begin{a= (3+2) *2;print A} '
10
A calculator under Linux