adb android shell

adb uninstall command doesn’t work in Bash shell for statement

For work reason, I need to uninstall and reinstall several apps in Android device. To do it quickly, it’s easy for me to write a script to do this so that I don’t need to type it again and again. Here is my script:

#adb uninstall
for i in `adb shell pm list packages|grep company|awk -F':' '{ print $2 }'`; do
echo adb uninstall "$i"
adb uninstall "$i"

The odd thing is `adb’ always prints “Failure” while ‘echo’ prints the right command.
The second line will work fine if uncomment it.

Anyone can help to figure out what the problem is?