adb shell循环命令,运行ADB命令的Bash脚本不会遍历设备列表

I have a simple bash script that iterates through a list of devices and runs adb shell commands to Android devices. The code is below:

echo "Displaying devices to be configured:"

adb devices | sed "1d ; $ d"

echo ""

echo "###########################"

echo "# #"

echo "# Starting configuration! #"

echo "# #"

echo "###########################"

echo ""

while read -r udid device usb product model device2; do

echo ""

echo $usb

echo ""

# INSTALL THE APPS

adb -s "$usb" install ./src/apps/1.apk

adb -s "$usb" install ./src/apps/quicksupport.apk

# SET WIFI OFF

adb -s "$usb" shell settings put global wifi_on 0

# SET SOUND TO 0

adb -s "$usb" shell service call audio 7 i32 3 i32 0 i32 1

# SET AUTO TIME ZONE OFF

adb -s "$usb" shell settings put global auto_time_zone 0

# SET INSTALL NON MARKET APPS ON

adb -s "$usb" shell settings put global install_non_market_apps 1

# REBOOT

adb -s "$usb" reboot

done <

echo ""

echo "###########################"

echo "# #"

echo "# Configuration complete! #"

echo "# #"

echo "###########################"

echo ""

When ran, the code will successfully run all configurations on one device. When plugged into two devices, the output reads as follows:

Displaying devices to be configured:

0123456789ABCDEF device

0123456789ABCDEF device

###########################

# #

# Starting configuration! #

# #

###########################

usb:336592896X

[100%] /data/local/tmp/1.apk

pkg: /data/local/tmp/1.apk

Failure [INSTALL_FAILED_ALREADY_EXISTS]

[100%] /data/local/tmp/quicksupport.apk

pkg: /data/local/tmp/quicksupport.apk

Failure [INSTALL_FAILED_ALREADY_EXISTS]

0123456789ABCDEF device usb:337641472X product:msm8960 model:msm8960 device:msm8960

Result: Parcel(00000000 '....')

###########################

# #

# Configuration complete! #

# #

###########################

It seems to return the remainder of the adb devices -l command and than break out of the loop. Is this an issue with bash? Is this an issue with adb? I've been trying to figure this out for days.

Note: The Result: Parcel(00000000 '....') output occurs directly after the sound is set to zero.

Note: Don't mind the Failure [INSTALL_FAILED_ALREADY_EXISTS], that occurs because the apps are already installed. That's not what I'm concerned about.

Note: Posting adb devices -l | hexdump -C

00000000 4c 69 73 74 20 6f 66 20 64 65 76 69 63 65 73 20 |List of devices |

00000010 61 74 74 61 63 68 65 64 0a 30 31 32 33 34 35 36 |attached.0123456|

00000020 37 38 39 41 42 43 44 45 46 20 20 20 20 20 20 20 |789ABCDEF |

00000030 64 65 76 69 63 65 20 75 73 62 3a 34 33 37 33 38 |device usb:43738|

00000040 37 32 36 34 58 20 70 72 6f 64 75 63 74 3a 6d 73 |7264X product:ms|

00000050 6d 38 39 36 30 20 6d 6f 64 65 6c 3a 6d 73 6d 38 |m8960 model:msm8|

00000060 39 36 30 20 64 65 76 69 63 65 3a 6d 73 6d 38 39 |960 device:msm89|

00000070 36 30 0a 30 31 32 33 34 35 36 37 38 39 41 42 43 |60.0123456789ABC|

00000080 44 45 46 20 20 20 20 20 20 20 64 65 76 69 63 65 |DEF device|

00000090 20 75 73 62 3a 33 33 36 35 39 32 38 39 36 58 20 | usb:336592896X |

000000a0 70 72 6f 64 75 63 74 3a 6d 73 6d 38 39 36 30 20 |product:msm8960 |

000000b0 6d 6f 64 65 6c 3a 6d 73 6d 38 39 36 30 20 64 65 |model:msm8960 de|

000000c0 76 69 63 65 3a 6d 73 6d 38 39 36 30 0a 0a |vice:msm8960..|

000000ce

解决方案

This is slightly more efficient and less error prone way of doing the same thing:

DeviceConfig () {

# INSTALL THE APPS

adb -s $1 install ./src/apps/1.apk

adb -s $1 install ./src/apps/quicksupport.apk

# SET WIFI OFF

adb -s $1 shell settings put global wifi_on 0

...

adb -s $1 reboot

}

for usb in $(adb devices -l | awk '/ device usb:/{print $3}'); do DeviceConfig $usb; done

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值