9

when I type adb devices in the shell I get something like this

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

HT06RPQ002T1
HT06RPQ002T1

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

Thanks

EDIT

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

Lukap
  • 31,523
  • 64
  • 157
  • 244

2 Answers2

18
adb devices | awk 'NR>1 {print $1}'
aphex
  • 3,372
  • 2
  • 28
  • 56
1
flag=false

while read -r device type
do
    if ! $flag
    then
        flag=true
        continue
    fi
    echo "$device"
done < <(adb devices)
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439