Lukap
Lukap

Reputation: 31963

Take the list of attached devices

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...

Upvotes: 9

Views: 22133

Answers (2)

Dennis Williamson
Dennis Williamson

Reputation: 359955

flag=false

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

Upvotes: 1

aphex
aphex

Reputation: 3412

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

Upvotes: 18

Related Questions