Linux 获取连接的设备列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10976453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:46:47  来源:igfitidea点击:

Take the list of attached devices

androidlinuxbashshell

提问by Lukap

when I type adb devicesin the shell I get something like this

当我adb devices在 shell 中输入时,我得到这样的信息

List of devices attached 
HT06RPQ002T1    device
HT06RPQ002T1    device

I want some shell script that will print just the ids of the phones for example in this case to print

我想要一些仅打印电话 ID 的 shell 脚本,例如在这种情况下打印

HT06RPQ002T1
HT06RPQ002T1

if more devices are attached to print more ids...

如果连接更多设备以打印更多 ID...

Thanks

谢谢

EDIT

编辑

I tried to put everything in a variable like this asd=adb devicesbut I do not have idea how to parse if I have one device attached or I have 10 devices...

我试图把所有东西都放在一个像 asd= 这样的变量中,adb devices但我不知道如果我连接了一个设备或者我有 10 个设备,我不知道如何解析......

采纳答案by aphex

adb devices | awk 'NR>1 {print }'

回答by Paused until further notice.

flag=false

while read -r device type
do
    if ! $flag
    then
        flag=true
        continue
    fi
    echo "$device"
done < <(adb devices)