使用shell进行数学运算
来源:互联网 发布:棉被羽绒被知乎 编辑:程序博客网 时间:2024/06/05 23:07
可以利用 let
、(())
、[]
进行基本的算术操作,高级操作使用bc
更加高效。
直接看代码把,输出很清楚。
let
[zhengweiwu 22:17 ~]$ no1=4[zhengweiwu 22:24 ~]$ no2=5[zhengweiwu 22:24 ~]$ let result=no1+no2[zhengweiwu 22:24 ~]$ echo $result9[zhengweiwu 22:24 ~]$ let result=result + 0.9 # 运算符两侧不能有空格-bash: let: +: syntax error: operand expected (error token is "+")[zhengweiwu 22:25 ~]$ let result=result+0.9 # 只能进行整数运算-bash: let: result=result+0.9: syntax error: invalid arithmetic operator (error token is ".9")[zhengweiwu 22:25 ~]$ echo $result9
[]
[zhengweiwu 22:26 ~]$ result=$[no1+no2][zhengweiwu 22:27 ~]$ echo $result9[zhengweiwu 22:27 ~]$ result=$[no1+no2+1][zhengweiwu 22:27 ~]$ echo $result10
(())
[zhengweiwu 22:28 ~]$ result=$((1+1))[zhengweiwu 22:28 ~]$ echo $result2[zhengweiwu 22:28 ~]$ result=$(( 10 +1))[zhengweiwu 22:29 ~]$ echo $result11
bc
[zhengweiwu 22:29 ~]$ echo "4*3.5" | bc14.0[zhengweiwu 22:29 ~]$ echo "4*3.54" | bc14.16[zhengweiwu 22:30 ~]$ result=$(echo "$no1*0.44" | bc) # 作为子shell计算结果[zhengweiwu 22:30 ~]$ echo $result1.76
[zhengweiwu 22:30 ~]$ echo "scale=2;3/8" | bc # 设定小数精度.37[zhengweiwu 22:31 ~]$ echo "scale=4;3/8" | bc.3750[zhengweiwu 22:31 ~]$ echo "scale=6;3/8" | bc.375000
[zhengweiwu 22:31 ~]$ no=100[zhengweiwu 22:33 ~]$ echo "obase=2;$no" | bc # 输出为2进制,默认输入进制为10进制1100100[zhengweiwu 22:33 ~]$ no=1100100[zhengweiwu 22:33 ~]$ echo "obase=10;ibase=2;$no" | bc # 指明输出进制和输入进制100
[zhengweiwu 22:34 ~]$ echo "sqrt(100)" | bc10[zhengweiwu 22:35 ~]$ echo "10^10" | bc10000000000
2 0
- 使用shell进行数学运算
- Shell脚本攻略03-使用shell进行数学运算
- linux shell进行数学运算
- 通过shell进行数学运算
- shell scripts_0 进行数学运算
- 通过shell进行数学运算的多种方式
- shell 之进行数学运算 let expr bc 中括号
- 【Bash百宝箱】shell中如何进行数学运算
- shell中的数学运算
- Linux Shell 数学运算
- shell中的数学运算
- shell变量数学运算
- shell 执行数学运算
- shell 执行数学运算
- Linux shell 数学运算
- shell中数学运算
- shell中数学运算
- shell 数学运算
- Quagga使用笔记1
- LR_EXIT函数的学习
- 端口映射---将局域网本地ip地址映射到外网
- Affymetrix芯片分析:获取差异表达基因系列一
- fragment的使用
- 使用shell进行数学运算
- 第二章第18题
- 回溯法求排列(二)
- 【Arduino学习笔记】手把手教你使用ESP8266----③整合Arduino篇
- php socket_select() 说明
- Js apply()、call()使用详解
- 好好的
- Linux 下grep命令
- ASIHTTPRequest类库简介和使用说明