zoukankan      html  css  js  c++  java
  • bc命令

    
    


    bc是unix/linux下的计算器,因此 除了可以作为计算器来使用 还可以作为命令行计算工具使用

    [root@server1 mnt]# 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'.
    1.1+1.2
    2.3

    [root@VM_0_15_centos ~]# echo 3+5|bc
    8
    [root@VM_0_15_centos ~]# echo 3.3+5.3|bc
    8.6
    [root@VM_0_15_centos ~]# echo 9.9-5.3|bc
    4.6
    [root@VM_0_15_centos ~]# echo 9-50|bc
    -41
    [root@VM_0_15_centos ~]# echo "scale=2;355/113"|bc #保留两位小数
    3.14
    [root@VM_0_15_centos ~]# echo "scale=6;355/113"|bc
    3.141592


    配合变量使用
    [root@VM_0_15_centos ~]# i=5
    [root@VM_0_15_centos ~]# i=`echo $i+6|bc`
    [root@VM_0_15_centos ~]# echo $i
    11


    $[]符号的运算式例子
    [root@VM_0_15_centos ~]# i=5
    [root@VM_0_15_centos ~]# i=$[i+6]
    [root@VM_0_15_centos ~]# echo $i
    11
    [root@VM_0_15_centos ~]# echo $[2*3]
    6
    [root@VM_0_15_centos ~]# echo $[2**3]
    8
    [root@VM_0_15_centos ~]# echo $[3/5]
    0
    [root@VM_0_15_centos ~]# echo $[3/2]
    1
    [root@VM_0_15_centos ~]# echo $[3%2]
    1
    [root@VM_0_15_centos ~]# echo $[3%5]
    3
    [root@VM_0_15_centos ~]# echo $[ 3 % 5 ]
    3
    [root@VM_0_15_centos ~]# echo $[ 3 / 5 ]
    0

    
    
  • 相关阅读:
    Elasticsearch 删除文档
    Elasticsearch 更新文档
    Elasticsearch 修改数据
    Elasticsearch 使用集群
    Elasticsearch 使用集群
    Elasticsearch 使用集群
    Elasticsearch 使用集群
    Elasticsearch 集群
    Elasticsearch 使用集群
    Elasticsearch 安装
  • 原文地址:https://www.cnblogs.com/liang545621/p/13036999.html
Copyright © 2011-2022 走看看