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 ...
随机推荐
- IOS,objective_C中用@interface和 @property 方式声明变量的区别
转自:http://www.cnblogs.com/letmefly/archive/2012/07/20/2601338.html 一直有疑问,在objective_C中声明变量会有 2种方式,今天 ...
- 【大话QT之十三】系统软件自己主动部署实现方案
本篇文章是对[大话QT之十二]基于CTK Plugin Framework的插件版本号动态升级文章的补充,在上篇文章中我们阐述的重点是新版本号的插件已经下载到plugins文件夹后应该怎样更新本地正在 ...
- c3p0 一个数据库链接的例子
首先需要准备三个依赖包 c3p0-0.9.5.2.jar.mchange-commons-java-0.2.11.jar.mysql-connector-java-5.1.47.jar 下载链接 ht ...
- Java中数据库连接的一些方法资料汇总
Java中Connection方法笔记 http://www.cnblogs.com/bincoding/p/6554954.html ResultSet详解(转) https://www.cnbl ...
- MongoDB 将Json数据直接写入MongoDB的方法
Json转Bson MongoDB中是以Bson数据格式进行存储的,Json字符串没有办法直接写入MongoDB 可以将Json字符串转换成DBObject或者Document,然后写入MongoDB ...
- Hadoop--mapreduce编程实例1
前提准备: 1.hadoop安装运行正常.Hadoop安装配置请参考:Ubuntu下 Hadoop 1.2.1 配置安装 2.集成开发环境正常.集成开发环境配置请参考 :Ubuntu 搭建Hadoop ...
- Ajax实现异步上传图片
要求:点击页面浏览按钮后,选择需要上传的图片,页面无刷新,将上传的图片展示出来 开发流程 一:在页面编写表单代码和js代码 <!DOCTYPE html PUBLIC "-//W3C/ ...
- 常见sql 写法总结
关于如何获取1对多数据中最大条数据的写法 例子: LEFT JOIN ( SELECT * FROM table AS n1 WHERE n1.ID IN ( SELECT MAX(id) FROM ...
- Python之Matplotlib库常用函数大全(含注释)
plt.savefig(‘test’, dpi = 600) :将绘制的图画保存成png格式,命名为 test plt.ylabel(‘Grade’) : y轴的名称 plt.axis([-1, 1 ...
- javaScript 的小技巧
20160314知识点的补充:a-1:最原始的操作要比函数调用快 <script type="text/javascript"> var min = Math.min( ...