當我發出命令時:
adb devices
我有這樣的結果:
List of devices attached
192.168.1.200:5555 offline
192.168.1.201:5555 device
192.168.1.202:5555 unauthorized
192.168.1.203:5555 device
我有這個 bash 腳本,但是因為它只能在連接的設備上作業而失敗:
#!/bin/bash
#init
a=$(adb devices | cut -f1 | cut -f1 -d\ );
echo $a;
for x in $a;
do
if [ "$x" == "List" ];
then continue;
fi;
echo $x
adb connect $x
done
如何僅從串列中的“設備”獲取 IP 并跳過串列中其他值的 IP?
uj5u.com熱心網友回復:
使用“grep”命令按名稱過濾,不需要額外的“cut”
a=$(adb devices | grep "device" | cut -f1 -d\);
uj5u.com熱心網友回復:
a=$(adb devices | sed "1 d" | grep "device" | cut -f1 -d\ );
添加了另外兩個過濾器:
sed "1 d" - 省略第一行,列印其他所有內容
grep "device" - 只列印包含“設備”的行
您可以洗掉 if 陳述句,因為它由sed過濾器處理。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/367136.html
