Shell下syntax error: operand expected (error token is “-”)
在这个监控实时网口速率的脚本中,第21,22行存在错误:
#!/bin/bash
#Modified by lifei4@datangmobile.cn
echo ===DTmobile NetSpeedMonitor===
sleep 1
echo loading...
sleep 1 ethn=$1 while true
do
RXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
sleep 1
RXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}') clear
echo -e "\t\t\t RX \t\t TX \t\t\t TIME" RX=$((${RXnext}-${RXpre}))
TX=$((${TXnext}-${TXpre})) if [ $RX -lt 1024 ];then
RX="${RX}B/s"
elif [ $RX -gt 1048576 ];then
RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
else
RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
fi if [ $TX -lt 1024 ];then
TX="${TX}B/s"
elif [[ $TX -gt 1048576 ]];then
TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
else
TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
fi echo -e "$ethn \t $RX $TX \t\t\t `date +%k:%M:%S` " done
修改后的文件
#!/bin/bash
#Modified by lifei4@datangmobile.cn
echo ===DTmobile NetSpeedMonitor===
sleep 1
echo loading...
sleep 1 ethn=$1 while true
do
RXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
sleep 1
RXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}') clear
echo -e "\t\t\t RX \t\t TX \t\t\t TIME" RX=$((RXnext-RXpre))
TX=$((TXnext-TXpre)) if [ $RX -lt 1024 ];then
RX="${RX}B/s"
elif [ $RX -gt 1048576 ];then
RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
else
RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
fi if [ $TX -lt 1024 ];then
TX="${TX}B/s"
elif [[ $TX -gt 1048576 ]];then
TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
else
TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
fi echo -e "$ethn \t $RX $TX \t\t\t `date +%k:%M:%S` " done
原因为,在$取值的时候,括号里面只需要跟变量即可(变量可自行进行计算),不需要对括号内进行运算的变量在进行取值操作。
RX=$((${RXnext}-${RXpre}))
TX=$((${TXnext}-${TXpre}))
修改后:
RX=$((RXnext-RXpre))
TX=$((TXnext-TXpre))
然后就没有然后了~~~
Shell下syntax error: operand expected (error token is “-”)的更多相关文章
- 由于MDK5.0A没有STM32F103程序错误 stm32f10x.h(298): error: #67: expected a "}"
转自:http://blog.163.com/lby147612@126/blog/static/17041045220150130438428/ 由于MDK4.72A没有STM32F030,所以升级 ...
- ..\USER\stm32f10x.h(428): error: #67: expected a "}" ADC1_2_IRQn = 18, /*!
MDK软件编译,出现如下错误: ..\USER\stm32f10x.h(428): error: #67: expected a "}" ADC1_2_IRQn = 18, /*! ...
- ubuntu1404下Apache2.4错误日志error.log路径位置
首先打开/etc/apache2路径下的apache2.conf文件,找到ErrorLog如下 ErrorLog ${APACHE_LOG_DIR}/error.log 这里{APACHE_LOG_D ...
- Ubuntu系统下MySQL读取文件数据ERROR解决
博文链接:http://haoyuanliu.github.io/2016/04/29/mysql/ 对,我是来骗访问量的!O(∩_∩)O~~ 在使用MySQL进行文件数据读取的时候,在终端敲入命令行 ...
- selenium启动报错“ incorrect JSON status mapping for 'unknown error' (500 expected)”
前面讲了工程启动报错“selenium启动报错Unable to read VR Path Registry from C:\Users\clinva\AppData\Local\openvr\ope ...
- linux下安装svn出现configure: error: We require OpenSSL; try --with-openssl
linux下安装svn出现configure: error: We require OpenSSL; try --with-openssl http://blog.csdn.net/woshixion ...
- fedora/centos下gcc编译出现gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory
fedora/centos下gcc编译出现gcc: error trying to exec 'cc1plus': execvp: No such file or directory解决办法 翻译自: ...
- MFC出现 error RC2108: expected numerical dialog constant错误解决办法
MFC在使用picture console控件之后往往会弹出这个错误:error RC2108: expected numerical dialog constant. 此时,双击这个错误,会跳到提示 ...
- Windows下使用ssh-add报错 Error connecting to agent: No such file or directory
Windows下使用ssh-add报错 Error connecting to agent: No such file or directory 环境信息 操作系统:windows 10 终端:Win ...
随机推荐
- hbase replication原理分析
本文只是从总体流程来分析replication过程,很多细节没有提及,下一篇文章准备多分析分析细节. replicationSource启动过程 org.apache.hadoop.hbase.r ...
- .net SQL分页
1.分页SQL declare @pagesize integer,@cpage integer; --变量定义 ; --页码大小 ; --当前页 ---@cpage 为 第一页的时候 --selec ...
- 地址url的split()方法使用;
stringObject.split(separator,howmany) 参数 描述 separator 必需.字符串或正则表达式,从该参数指定的地方分割 stringObject. howmany ...
- spring的容器(控制反转、依赖注入)
一.spring的容器 ”容器“是spring的一个重要概念,其主要作用是完成创建成员变量,并完成装配. 而容器的特点”控制反转“和”依赖注入“是两个相辅相成的概念. 控制反转:我们在使用一个类型的实 ...
- PHP案例:学生信息管理系统
-- Database: test -- 表的结构 message CREATE TABLE `message` ( `id` tinyint(1) NOT NULL PRIMARY KEY AUTO ...
- R学习----数据类型
今天开始学习R语言了,没原因,就是想学 本人开发环境在ubuntu 16.04 LTS下 R命令提示符 终端直接输入R进入交互模式进行R学习.如下图 R脚本 # My first program in ...
- java 检测字符串中文乱码
1.检测是否为乱码 public static boolean isMessyCode(String strName) { Pattern p = Pattern.compile("\\s* ...
- 【转】Oracle Sys和system用户、sysdba 和sysoper系统权
一:最重要的区别,存储的数据的重要性不同 [sys]所有oracle的数据字典的基表和视图都存放在sys用户中,这些基表和视图对于oracle的运行是至关重要的,由数据库自己维护,任何用户都不能手动更 ...
- Ubuntu14.04中安装Sublime_Text_3
Sublime Text 简介 Sublime Text 是一款流行的文本编辑器软件,有点类似于TextMate,跨平台,可运行在Linux.Windows和Mac OS X.也是许多程序员喜欢使用的 ...
- MS SqlServer 2008R2- Sql语句循环遍历生成百条随机数
Sql语句,循环遍历生成区间5~20的随机数语句如下: are @i int DECLARE @Result INT DECLARE @Upper INT DECLARE @Lower INT ) ) ...