1.shell处理两数相加时报错:

req_all=$(($hits+$misses))

error: invalid arithmetic operator (error token is "

查询原因发现:

hits=`$REDISCLI -h $IP -p $PORT info 2>&1 |grep -w keyspace_hits |cut -d : -f2`
misses=`$REDISCLI -h $IP -p $PORT info 2>&1 |grep -w keyspace_misses |cut -d : -f2`
echo $hits
echo $misses

变量的值结尾需要处理,所以要计算的话要用下面的方式
req_all=$((${hits//$'\r'}+${misses//$'\r'}))

计算百分比的方法:

hit_ratio=$(printf "%0.1f" $((${hits//$'\r'}*100/${req_all})))

hit_ratio=`awk 'BEGIN{printf "%.2f\n",('${hits//$'\r'}'/'${req_all}')*100}'`

shell计算小问题的更多相关文章

  1. linux运维自动化shell脚本小工具

    linux运维shell 脚本小工具,如要分享此文章,请注明文章出处,以下脚本仅供参考,若放置在服务器上出错,后果请自负 1.检测cpu剩余百分比 #!/bin/bash #Inspect CPU # ...

  2. shell讲解-小案例

    shell讲解-小案例 一.文件拷贝输出检查 下面测试文件拷贝是否正常,如果cp命令并没有拷贝文件myfile到myfile.bak,则打印错误信息.注意错误信息中basename $0打印脚本名.如 ...

  3. shell脚本小案例

    1.获取远程ftp数据到本地目录 #!/bin/bash ftp -n<<! open 135.0.24.19 user exchange exchange binary cd /idep ...

  4. python 练习题:小明的成绩从去年的72分提升到了今年的85分,请计算小明成绩提升的百分点

    # -*- coding: utf-8 -*- # 小明的成绩从去年的72分提升到了今年的85分,请计算小明成绩提升的百分点,并用字符串格式化显示出'xx.x%',只保留小数点后1位. s1 = 72 ...

  5. shell之小括号、中括号、大括号

    1.Shell中变量的原形:${var}  一串命令的执行 #等价于 $ var=test $ echo $var test #例如,用在这个位置 $ echo ${var}AA testAA 2.命 ...

  6. shell 计算2

    转载 http://www.th7.cn/system/lin/201309/44683.shtml expr bc 在Linux下做算术运算时你是如何进行的呢?是不是还在用expr呢?你会说我还会b ...

  7. shell脚本小集锦

    1) 如何向脚本传递参数 ? ./script argument 例子: 显示文件名称脚本 ./show.sh file1.txt cat show.sh #!/bin/bash 2) 如何在脚本中使 ...

  8. shell脚本小实例

    本文收集了一堆的shell脚本技巧,我说过,我写博客主要是作一些学习笔记,方便自己查阅,所以,我会搞出这么一篇文章,也没有什么不可理解的.关于这些技巧的出处,诶,我也忘了,可能来自theunixsch ...

  9. NSAttributedString宽高计算小技巧

    通常对于CoreText之类自己实现绘制的控件来说,计算富文本的宽高事实上须要依赖CTFramesetterSuggestFrameSizeWithConstraints这种方法. 但有些时候.我们可 ...

随机推荐

  1. Ubuntu下Sublime Text 3解决无法输入中文的方法

    Ubuntu下Sublime Text 3解决无法输入中文的方法_百度经验http://jingyan.baidu.com/article/f3ad7d0ff8731609c3345b3b.html ...

  2. 【Java EE 学习 49 上】【Spring学习第一天】【基本配置】

    一.HelloWorld 需要的jar文件(以2.5.5为例):spring.jar,common-logging.jar 1.新建类com.kdyzm.spring.helloworld.Hello ...

  3. 利用stack结构,将中缀表达式转换为后缀表达式并求值的算法实现

    #!/usr/bin/env python # -*- coding: utf-8 -*- # learn <<Problem Solving with Algorithms and Da ...

  4. 【转载】Linux常用命令列表

    原文地址:http://www.cnblogs.com/Javame/p/3968343.html 1 目录与文件操作 1.1 ls(初级) 使用权限:所有人 功能 : 显示指定工作目录下之内容(列出 ...

  5. 关于opengl库

    The 64-bit OpenGL import library is included in the Windows SDK and gets installed to %ProgramFiles% ...

  6. Html中鼠标悬停显示二级菜单的两种方法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. C#(委托a)

    C#(委托a) public delegate double TheOperator(double x, double y); public class Operators { static publ ...

  8. Official online document, install svn server in centOS

    http://www.krizna.com/centos/install-svn-server-on-centos-6/

  9. Difinition Of Done

    A Story is Sprint ready (Rally Defined) when............. The story has well defined and testable ac ...

  10. MD5 、 加密工具

    package com.cgcyiliao.server.util; import java.security.MessageDigest; import java.security.NoSuchAl ...