Search code examples
macosbashsdkadb

get processor using adb inside bash script


I'm trying to write a bash script (on my mac) that will get the SDK version and the name of the processor (and use it later) from an android device. I assume the processor will be intel or arm.

so far, I have:

#!/bin/bash

echo "HI $USER" 

# get the sdk version
SDK = $(adb shell getprop ro.build.version.sdk | tr -d '\r')

PROCESSOR = arm
# get processor type (arm or intel)
if ["$(adb shell cat /proc/cpuinfo | tr -d '\r' | grep Processor | grep ARM)" = ""]
then
    PROCESSOR = intel
fi

echo $SDK
echo $PROCESSOR

and I get the following errors: line 6: SDK: command not found line 8: PROCESSOR: command not found line 43: [Processor : ARMv7 Processor rev 0 (v7l): command not found

But when I write:

echo $(adb shell getprop ro.build.version.sdk | tr -d '\r')

I see the correct version of the SDK.

can you plz help? I must be missing something because it should be super easy..


Solution

  • Get rid of the spaces before and after the = sign. For example change

        SDK = $(adb shell getprop ro.build.version.sdk | tr -d '\r')
    

    to

        SDK=$(adb shell getprop ro.build.version.sdk | tr -d '\r')
    

    Do this for all the variables.

    For more on this Bash script variable declaration - command not found