Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm incorporating a script snippet which determines Android version via: adb shell getprop which returns: 4.1.2 or 4.0.4

The snippet currently looks like this:

if [ "$(adb shell getprop" == "4.1.2" ]; then
elif [ "$(adb shell getprop" == "4.0.4" ]; then
echo $rw_path

I thought adb might return the value via stderr just as it does with push/pull output so I tried this as well (not sure if that's the right way of doing this though):

if [ "$(adb shell getprop 2>&1)" == "4.1.2" ]; then
elif [ "$(adb shell getprop 2>&1)" == "4.0.4" ]; then
echo $rw_path

Tried -eq operator instead of == but it warns that "integer expression expected".

I then tried this to make sure it actually compares something:

version=$(adb shell getprop 2>&1)
if [ "$version" == "4.1.2" ]; then
elif [ "$version" == "4.0.4" ]; then
echo $version
echo $rw_path

Tried unquoting "$variable" to no luck. The above outputs "4.0.4" or "4.1.2" for $version as expected but in all the attempts above it fails to output anything for $rw_path.

What am I doing wrong?!

Thanks in advance.

EDIT: Tried double brackets as suggested below with no luck. How come "4.0.4" output is not equal to "4.0.4" string? Is whitespace relevant in comparison? Can I trim the output first? Just a thought...

share|improve this question
Whitespace is relevant. Your script works ok, the problem is with what adb returns. – Laurentiu Roescu Sep 4 '13 at 18:55
Try echo "-$rw_path-" to see if returned string has some whitespaces in it. – Laurentiu Roescu Sep 4 '13 at 18:56
Tried that and only the first dash was returned which confirmed that adb returns a new line at the end just as Mark Wagner said. Thanks! – Vigintas Labakojis Sep 4 '13 at 19:05
up vote 6 down vote accepted

I suspect there is an "\r" in the output of the adb command. Try

$(adb shell getprop | tr -d '\r')

share|improve this answer
Superb! You're a genius. I'll remember that! – Vigintas Labakojis Sep 4 '13 at 19:03
god bless you :-) – Tim Boland Feb 28 '15 at 17:10

Try making those brackets around your test double brackets.

share|improve this answer
Thanks but that didn't help. – Vigintas Labakojis Sep 4 '13 at 18:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.