Reputation: 2783
I am writing a bash script to connect to a device via adb
and then manipulate files. I prompt the user for an IP address to connect to, and then connect using adb connect $IP
. However, I want to verify that the device was successfully connected, and abort the script if it was not.
I am thinking I would accomplish this with something like adb connect $IP | cat
, and then check the output for the words "unable to connect" (I am fairly new to bash scripting, so this might be pretty basic). How would I write this in my script?
Upvotes: 1
Views: 1974
Reputation: 28
Another way to do this would be using the command "adb devices", which only lists connected devices and outputs nothing when there's no device connected. So you can take advantage of that. If you're not sure how to do it, read this.
Of course, if there are other devices connected, that would be problematic. But I'm assuming you take for granted that there are no other devices. In case you'd want to take this into account, you can just check "adb devices" output before and after..
Upvotes: 1