Shell script works in bash but not on ‘adb shell’

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error Shell script works in bash but not on ‘adb shell’ on this date .

Below shell script works perfectly fine in bash shell. But produces an error in android shell. May be it has got to do something with the shell that android is using. But how can I resolve it? If not a perfect solution, an hack would also do for me.

Shell-script :

    local x
    echo "x - $x"
    if [ "${x}" = " " -o -z "${x}" ]; then
    echo "A - ${a} X - {x}"

func "abc=efg"

O/p In android shell,

root:/ #                                                  
x - =
/system/bin/[14]: [: =: missing second argument
A - S X - {x}

O/p on bash shell(Linux):

PC:~$ ./ 
x - =
A - S X - {x}


When the value of $x is just =, it looks like:

if [ = = " " -o -z = ]; then

and it’s apparently getting confused by the = that should be a value rather than an operator.

Change it to:

if [ "x${x}" = "x " -o "x${x}" = "x" ]; then