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

    
    
  • 相关阅读:
    linux_crontab_定时删除
    bigdata_zookeeper 可视化界面zkui
    bigdata_ Kafka集群模式部署
    大数据_zookeeper环境搭建中的几个坑
    实战-130W表增加字段耗时
    每天一个linux命令
    nginx重启报找不到nginx.pid的解决方法
    log4j配置
    mysql select 1
    查看mysql语句运行时间
  • 原文地址:https://www.cnblogs.com/l10n/p/13036999.html
Copyright © 2011-2022 走看看