Home > Enterprise >  Get the exact value from android getprop
Get the exact value from android getprop

Time:09-10

I wish to get specific value of properties from adb command getprop

To get specific value I use:

adb shell getprop ro.product.display_name
adb shell getprop ro.bootloader
adb shell getprop ro.serialno
adb shell getprop ro.product.model

Result example:

Galaxy Watch5
RFT4JD6GHK
RGHJKABVGTS
SM-R860

But this is not good, cos for each value, I need to do getprop each time. I wish to ask it once per device and then parse the result to get values.

Something like:

adb shell getprop

and then what I get from stdout is long list with all properties and values

...
[ro.build.version.release]: [4.2.2]
[ro.product.display_name]: [Galaxy Watch5]
[ro.bootloader]: [RFT4JD6GHK]
[ro.hardware]: [qcom]
[ro.opengles.version]: [196108]
[ro.product.brand]: [Verizon]
[ro.product.manufacturer]: [samsung]
[ro.serialno]: [RGHJKABVGTS]
[ro.product.model]: [SM-R860]
...

How to parse this big list end get same result as separate commands? I try bellow but I get the whole thing with brackets:

adb shell getprop | grep "ro.product.display_name\|ro.bootloader\|ro.serialno\|ro.product.model"

Result:

[ro.product.display_name]: [Galaxy Watch5]
[ro.bootloader]: [RFT4JD6GHK]
[ro.serialno]: [RGHJKABVGTS]
[ro.product.model]: [SM-R860]

CodePudding user response:

I solve it, but I'm not sure if there is easier solution:

adb shell getprop | grep 'ro.product.display_name\|ro.bootloader\|ro.serialno\|ro.product.model' | cut -d ":" -f 2 | sed 's:^..\(.*\).$:\1:'

CodePudding user response:

Using awk and defining an array with the keys you want (ro.product.display_name used as an example here), you can do

adb shell getprop | awk -F '[][:]' 'BEGIN {keys["ro.product.display_name"]  } $2 in keys {print $5}'
  • Related