Looking for android version with ADB

I was trying to get my android version number with ADB (as I didn’t want to make excessive use of my fingers on a screen, you know ;-) ). I wanted to do it so I could make some scripts, but I didn’t really found a cool way to do so.  Thankfully, android shell has a command wich will tell us all device info:  getprop.

As this is an android shell stuff and not ADB itself, we’ll have to launch adb shell against it, and then parse the output, I’m using awk here to parse it

I’ll change awk internal field separator (IFS) with the -F flag to parse the output into key-value stuff and print only the value, I already knew the key, wich, for android version, is “build.version.release”

We can parse, csv with awk the same way as we’ll be doing this:

cat foo.csv| awk -F ","  '/pattern/ {print $1 }'

At the end we’ll get version with just this simple piece of code:

version=$(adb shell getprop |awk -F":" '/build.version.release/ { print $2 }')

Update: I wanted it cleaner, so I removed [ and ] with tr.

version=$(adb shell getprop |awk -F":" '/build.version.release/ { print $2 }')|tr -d '[]'

Amazingly usefull for android debugging!

2 thoughts on “Looking for android version with ADB