For example, I want to check if a directory exists on the phone.
R=$(adb shell 'ls /mnt/; echo $?' | tail -1);
$ echo $R
0
$ if [ "$R" -ne 0 ]; then echo "Path doesn't exist"; else echo "Path exists"; fi
: integer expression expected
Path exists
What's wrong with R? Ok, try it with another variable which is definitely 0.
$ x=0
$ if [ "$x" -ne 0 ]; then echo "Path doesn't exist"; else echo "Path exists"; fi
Path exists
$ echo "|$x|"
|0|
$ echo "|$R|"
|0
The second pipe isn't printed. Is there a character after 0? Try to trim:
$ R=$(adb shell 'ls /mnt/; echo $?' | tail -1 | xargs)
$ echo "|$R|"
|0
I'm out of ideas.