简体   繁体   English

Shell脚本:如何读取和存储adb设备的响应

[英]Shell Scripting: How to read the response of adb devices and store it

I am trying to make a small shell script that would pass some adb commands, reboot the device, and once the device reboots, again pass some adb commands. 我正在尝试制作一个小的shell脚本,该脚本将传递一些adb命令,重新启动设备,一旦设备重新引导,再次传递一些adb命令。 I was thinking of passing adb devices at regular intervals through out the period the device is rebooting so as to know when the next adb command could be passed(not sure there are any other better methods for doing this). 我正在考虑在整个设备重新引导期间定期传递adb设备,以便知道何时可以传递下一个adb命令(不确定是否有其他更好的方法可以执行此操作)。 For this purpose I need to check the response of each adb devices command. 为此,我需要检查每个adb devices命令的响应。 Is there any method to read this response? 有什么方法可以读取此回复? I am a novice in shell scripts. 我是shell脚本的新手。 Kindly excuse it the method I am adopting to achieve this task is not correct. 请原谅我为实现此任务而采用的方法不正确。 Any help or suggestions would be much appreciated. 任何帮助或建议,将不胜感激。

You can make an if statement from the response: 您可以从响应中做出if语句:

device=$(adb devices) 
while true 
do 
sleep 5 
if [ "$(adb devices)"="$device" ];
    then
    echo "device rebooted"
    break
  fi
done

This would check ten times in an intervall of 5 secs. 这将在5秒的间隔中检查十次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM