1 bc命令
1直接进入其命令行执行 bc -q 回车
2写个文件一起执行 bc -q bc-test.bc(纯文本)
3直接在shell中管道符交由bc执行数学运算 echo 2+3|bc
4可处理进制转换,设置精度
2 expr命令
可以是数字或者字符串
3let 命令
4$((expr))
5 ((a++))这种自加操作不用赋值,a从-变为了1,但是其他运算 $((b=b+5))这里是需要赋值的否则b不会变的
[lsx@tcbj3-slcdb01 tmp]$ echo 3+9|bc
12
[lsx@tcbj3-slcdb01 tmp]$ echo 3+9
3+9
[lsx@tcbj3-slcdb01 tmp]$ echo "scale=2;3%2"|bc
0
[lsx@tcbj3-slcdb01 tmp]$ echo "3%2"|bc
1
[lsx@tcbj3-slcdb01 tmp]$ echo "scale=2;3/2"|bc
1.50
[lsx@tcbj3-slcdb01 tmp]$ echo "ibase=16;A"|bc
10
[lsx@tcbj3-slcdb01 tmp]$ expr 3+9
3+9
[lsx@tcbj3-slcdb01 tmp]$ expr 3 + 9
12
[lsx@tcbj3-slcdb01 tmp]$ str=123454
[lsx@tcbj3-slcdb01 tmp]$ echo $str
123454
[lsx@tcbj3-slcdb01 tmp]$ echo $str+1
123454+1
[lsx@tcbj3-slcdb01 tmp]$ echo $(str+1)
-bash: str+1: command not found
[lsx@tcbj3-slcdb01 tmp]$ echo $str+1|bc
123455
[lsx@tcbj3-slcdb01 tmp]$ echo length $str
length 123454
[lsx@tcbj3-slcdb01 tmp]$ expr length $str
6
[lsx@tcbj3-slcdb01 tmp]$ expr substr $str 0 2
[lsx@tcbj3-slcdb01 tmp]$ echo $str
123454
[lsx@tcbj3-slcdb01 tmp]$ expr substr $str 1 3
123
[lsx@tcbj3-slcdb01 tmp]$ let a=2+9
[lsx@tcbj3-slcdb01 tmp]$ echo $a
11
[lsx@tcbj3-slcdb01 tmp]$ let a=2**3
[lsx@tcbj3-slcdb01 tmp]$ echo $a
8
[lsx@tcbj3-slcdb01 tmp]$ echo $((3+5))
8
[lsx@tcbj3-slcdb01 tmp]$ ((a=a+4))
[lsx@tcbj3-slcdb01 tmp]$ echo $a
4
[lsx@tcbj3-slcdb01 tmp]$ d=$((e=a+1))
[lsx@tcbj3-slcdb01 tmp]$ echo $e $d
5 5
[lsx@tcbj3-slcdb01 tmp]$ echo `date`
Wed Jun 12 16:08:57 CST 2019
[lsx@tcbj3-slcdb01 tmp]$ echo `date +%Y%m%d`
20190612
#注意空格
[dcadmin@tcbj3-dmdis01 ~]$ if [ "ok" == "ok" ];then echo "it\'s right";else echo "wrong"; fi
it\'s right