如何根据输出过滤数据和执行命令
我正在使用以下Shell脚本进行CERTAIL数据
测试。SH
adb shell dumpsys battery | awk '/Battery current/{print}'
我在终端中的输出下方
Battery current : -286
如何检查电池电流值是否为gt> -1000然后执行命令“命令1” 否则执行“命令2”,
请帮助
I am using below shell script for getting certail data
test.sh
adb shell dumpsys battery | awk '/Battery current/{print}'
I get below output in terminal
Battery current : -286
How to check if Battery current value is > -1000 then execute an command "Command1"
else execute "Command 2"
Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需使用
awk
提取所需的字段:如果要将该值放在变量中:
现在您可以在语句中使用
中使用它:
Just use
awk
to extract the field you want:If you want to put that value in a variable:
And now you can use that in an
if
statement:使用
awk
,您可以使用System
函数,该功能执行CMD并返回其退出状态Using
awk
, you can use thesystem
function which executes cmd and returns its exit status通用模板就是这样:
您的具体情况就像:
The generic template would be like this :
Your specific case would be like :