I plugged several android devices to my laptop. And I can list their SN by
adb devices
output:
List of devices attached
015d4a826e0ffb0f device
015d4a826e43fb16 device
015d41d830240b11 device
015d2578a7280b02 device
I want to perform some operations on every device, like
adb -s $device install foo.apk
But I don't know how to let variable device
iterate all the devices obtained by adb devices
.
One way to do it in bash
. Read the output of your command and iterate it on the second column using a while loop
.
while read sn device; do
adb -s "$sn" install foo.apk
done < <(adb devices | sed '1d')
Main trick is to separate serial of device from other output. You need to cut off header and second column. Something like this would work:
for DEVICE in `adb devices | grep -v "List" | awk '{print $1}'`
do
adb -s $DEVICE install foo.apk
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With